@forge/storage 1.5.15 → 1.6.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/README.md +2 -1
- package/out/__test__/global-storage.test.js +255 -41
- package/out/entity-storage/query-api.js +56 -19
- package/out/entity-storage/storage-builder.js +2 -0
- package/out/errors.js +1 -1
- package/out/global-storage.d.ts +6 -1
- package/out/global-storage.d.ts.map +1 -1
- package/out/global-storage.js +52 -14
- package/out/gql-queries.js +86 -82
- package/out/query-api.js +19 -5
- package/package.json +5 -3
|
@@ -2,17 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomEntityBuilder = exports.CustomEntityIndexBuilder = void 0;
|
|
4
4
|
class CustomEntityQueryBuilder {
|
|
5
|
+
globalStorage;
|
|
6
|
+
queryOptions;
|
|
5
7
|
constructor(globalStorage, queryOptions = {}) {
|
|
6
8
|
this.globalStorage = globalStorage;
|
|
7
9
|
this.queryOptions = queryOptions;
|
|
8
|
-
this.queryOptions =
|
|
10
|
+
this.queryOptions = {
|
|
11
|
+
...queryOptions
|
|
12
|
+
};
|
|
9
13
|
}
|
|
10
14
|
clone(overrides) {
|
|
11
|
-
return new (Object.getPrototypeOf(this).constructor)(this.globalStorage,
|
|
15
|
+
return new (Object.getPrototypeOf(this).constructor)(this.globalStorage, {
|
|
16
|
+
...this.queryOptions,
|
|
17
|
+
...overrides
|
|
18
|
+
});
|
|
12
19
|
}
|
|
13
20
|
where(condition) {
|
|
14
21
|
return this.clone({
|
|
15
|
-
range:
|
|
22
|
+
range: {
|
|
23
|
+
...condition
|
|
24
|
+
}
|
|
16
25
|
});
|
|
17
26
|
}
|
|
18
27
|
sort(sort) {
|
|
@@ -32,7 +41,7 @@ class CustomEntityQueryBuilder {
|
|
|
32
41
|
}
|
|
33
42
|
async getOne() {
|
|
34
43
|
const { results } = await this.limit(1).getMany();
|
|
35
|
-
return results
|
|
44
|
+
return results?.[0];
|
|
36
45
|
}
|
|
37
46
|
async getMany() {
|
|
38
47
|
if (!this.queryOptions.entityName) {
|
|
@@ -41,7 +50,7 @@ class CustomEntityQueryBuilder {
|
|
|
41
50
|
if (!this.queryOptions.indexName) {
|
|
42
51
|
throw new Error('indexName is mandatory');
|
|
43
52
|
}
|
|
44
|
-
const queryOptions =
|
|
53
|
+
const queryOptions = { ...this.queryOptions };
|
|
45
54
|
if (!queryOptions.filterOperator && queryOptions.filters) {
|
|
46
55
|
queryOptions.filterOperator = 'and';
|
|
47
56
|
}
|
|
@@ -49,41 +58,55 @@ class CustomEntityQueryBuilder {
|
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
class CustomEntityAndFilterQueryBuilder extends CustomEntityQueryBuilder {
|
|
61
|
+
globalStorage;
|
|
62
|
+
queryOptions;
|
|
52
63
|
constructor(globalStorage, queryOptions = {}) {
|
|
53
64
|
super(globalStorage, queryOptions);
|
|
54
65
|
this.globalStorage = globalStorage;
|
|
55
66
|
this.queryOptions = queryOptions;
|
|
56
|
-
this.queryOptions =
|
|
67
|
+
this.queryOptions = {
|
|
68
|
+
...queryOptions
|
|
69
|
+
};
|
|
57
70
|
}
|
|
58
71
|
andFilter(field, condition) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
const newQueryOptions = {
|
|
73
|
+
...this.queryOptions
|
|
74
|
+
};
|
|
75
|
+
newQueryOptions.filters = [...(this.queryOptions.filters ?? []), { property: field, ...condition }];
|
|
62
76
|
newQueryOptions.filterOperator = 'and';
|
|
63
77
|
return new CustomEntityAndFilterQueryBuilder(this.globalStorage, newQueryOptions);
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
class CustomEntityOrFilterQueryBuilder extends CustomEntityQueryBuilder {
|
|
81
|
+
globalStorage;
|
|
82
|
+
queryOptions;
|
|
67
83
|
constructor(globalStorage, queryOptions = {}) {
|
|
68
84
|
super(globalStorage, queryOptions);
|
|
69
85
|
this.globalStorage = globalStorage;
|
|
70
86
|
this.queryOptions = queryOptions;
|
|
71
|
-
this.queryOptions =
|
|
87
|
+
this.queryOptions = {
|
|
88
|
+
...queryOptions
|
|
89
|
+
};
|
|
72
90
|
}
|
|
73
91
|
orFilter(field, condition) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
const newQueryOptions = {
|
|
93
|
+
...this.queryOptions
|
|
94
|
+
};
|
|
95
|
+
newQueryOptions.filters = [...(this.queryOptions.filters ?? []), { property: field, ...condition }];
|
|
77
96
|
newQueryOptions.filterOperator = 'or';
|
|
78
97
|
return new CustomEntityOrFilterQueryBuilder(this.globalStorage, newQueryOptions);
|
|
79
98
|
}
|
|
80
99
|
}
|
|
81
100
|
class CustomEntityFilterQueryBuilder extends CustomEntityQueryBuilder {
|
|
101
|
+
globalStorage;
|
|
102
|
+
queryOptions;
|
|
82
103
|
constructor(globalStorage, queryOptions = {}) {
|
|
83
104
|
super(globalStorage, queryOptions);
|
|
84
105
|
this.globalStorage = globalStorage;
|
|
85
106
|
this.queryOptions = queryOptions;
|
|
86
|
-
this.queryOptions =
|
|
107
|
+
this.queryOptions = {
|
|
108
|
+
...queryOptions
|
|
109
|
+
};
|
|
87
110
|
}
|
|
88
111
|
andFilter(field, condition) {
|
|
89
112
|
return new CustomEntityAndFilterQueryBuilder(this.globalStorage, this.queryOptions).andFilter(field, condition);
|
|
@@ -93,25 +116,39 @@ class CustomEntityFilterQueryBuilder extends CustomEntityQueryBuilder {
|
|
|
93
116
|
}
|
|
94
117
|
}
|
|
95
118
|
class CustomEntityIndexBuilder {
|
|
119
|
+
globalStorage;
|
|
120
|
+
queryOptions;
|
|
96
121
|
constructor(globalStorage, queryOptions = {}) {
|
|
97
122
|
this.globalStorage = globalStorage;
|
|
98
123
|
this.queryOptions = queryOptions;
|
|
99
|
-
this.queryOptions =
|
|
124
|
+
this.queryOptions = {
|
|
125
|
+
...queryOptions
|
|
126
|
+
};
|
|
100
127
|
}
|
|
101
128
|
index(name, indexOptions) {
|
|
102
|
-
const indexProperties = indexOptions ?
|
|
103
|
-
return new CustomEntityFilterQueryBuilder(this.globalStorage,
|
|
129
|
+
const indexProperties = indexOptions ? { indexName: name, ...indexOptions } : { indexName: name };
|
|
130
|
+
return new CustomEntityFilterQueryBuilder(this.globalStorage, {
|
|
131
|
+
...this.queryOptions,
|
|
132
|
+
...indexProperties
|
|
133
|
+
});
|
|
104
134
|
}
|
|
105
135
|
}
|
|
106
136
|
exports.CustomEntityIndexBuilder = CustomEntityIndexBuilder;
|
|
107
137
|
class CustomEntityBuilder {
|
|
138
|
+
globalStorage;
|
|
139
|
+
queryOptions;
|
|
108
140
|
constructor(globalStorage, queryOptions = {}) {
|
|
109
141
|
this.globalStorage = globalStorage;
|
|
110
142
|
this.queryOptions = queryOptions;
|
|
111
|
-
this.queryOptions =
|
|
143
|
+
this.queryOptions = {
|
|
144
|
+
...queryOptions
|
|
145
|
+
};
|
|
112
146
|
}
|
|
113
147
|
entity(name) {
|
|
114
|
-
return new CustomEntityIndexBuilder(this.globalStorage,
|
|
148
|
+
return new CustomEntityIndexBuilder(this.globalStorage, {
|
|
149
|
+
...this.queryOptions,
|
|
150
|
+
entityName: name
|
|
151
|
+
});
|
|
115
152
|
}
|
|
116
153
|
}
|
|
117
154
|
exports.CustomEntityBuilder = CustomEntityBuilder;
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EntityStorageBuilder = void 0;
|
|
4
4
|
const query_api_1 = require("./query-api");
|
|
5
5
|
class EntityStorageBuilder {
|
|
6
|
+
entityName;
|
|
7
|
+
globalStorage;
|
|
6
8
|
constructor(entityName, globalStorage) {
|
|
7
9
|
this.entityName = entityName;
|
|
8
10
|
this.globalStorage = globalStorage;
|
package/out/errors.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.APIError = exports.getErrorMessage = exports.getErrorMessageFromCode = void 0;
|
|
4
4
|
const getErrorMessageFromCode = (code, message) => {
|
|
5
|
-
return message
|
|
5
|
+
return message ?? code;
|
|
6
6
|
};
|
|
7
7
|
exports.getErrorMessageFromCode = getErrorMessageFromCode;
|
|
8
8
|
const getErrorMessage = (statusCode) => {
|
package/out/global-storage.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FetchMethod } from './index';
|
|
2
2
|
import { CustomEntityListOptions, ListOptions } from './query-interfaces';
|
|
3
3
|
import { SharedStorageAdapter } from './storage-adapter';
|
|
4
|
+
import type { Metrics } from '@forge/util/packages/metrics-interface';
|
|
4
5
|
interface ListResults {
|
|
5
6
|
results: {
|
|
6
7
|
key: string;
|
|
@@ -8,11 +9,14 @@ interface ListResults {
|
|
|
8
9
|
}[];
|
|
9
10
|
nextCursor?: string;
|
|
10
11
|
}
|
|
12
|
+
export declare type StoreType = 'typed' | 'untyped';
|
|
13
|
+
export declare type OperationType = 'get' | 'set' | 'query' | 'delete';
|
|
11
14
|
export declare class GlobalStorage implements SharedStorageAdapter {
|
|
12
15
|
private getAppContextAri;
|
|
13
16
|
private apiClient;
|
|
17
|
+
private readonly getMetrics;
|
|
14
18
|
private readonly endpoint;
|
|
15
|
-
constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod);
|
|
19
|
+
constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod, getMetrics: () => Metrics | undefined);
|
|
16
20
|
private doGetAppContextAri;
|
|
17
21
|
get(key: string): Promise<any>;
|
|
18
22
|
getSecret(key: string): Promise<any>;
|
|
@@ -30,6 +34,7 @@ export declare class GlobalStorage implements SharedStorageAdapter {
|
|
|
30
34
|
private buildRequest;
|
|
31
35
|
private query;
|
|
32
36
|
private mutation;
|
|
37
|
+
private wrapInMetric;
|
|
33
38
|
}
|
|
34
39
|
export {};
|
|
35
40
|
//# sourceMappingURL=global-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-storage.d.ts","sourceRoot":"","sources":["../src/global-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"global-storage.d.ts","sourceRoot":"","sources":["../src/global-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAEtE,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;AAcD,oBAAY,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAC5C,oBAAY,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AA+B/D,qBAAa,aAAc,YAAW,oBAAoB;IAGtD,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;gBAE5C,gBAAgB,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,WAAW,EACb,UAAU,EAAE,MAAM,OAAO,GAAG,SAAS;IAGxD,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;IAU3C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOxC,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;IAO5E,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAU1D,WAAW;YAUX,iBAAiB;IAU/B,OAAO,CAAC,YAAY;YAUN,KAAK;YAML,QAAQ;YAsBR,YAAY;CAyC3B"}
|
package/out/global-storage.js
CHANGED
|
@@ -25,10 +25,14 @@ async function getResponseBody(response) {
|
|
|
25
25
|
return responseBody.data;
|
|
26
26
|
}
|
|
27
27
|
class GlobalStorage {
|
|
28
|
-
|
|
28
|
+
getAppContextAri;
|
|
29
|
+
apiClient;
|
|
30
|
+
getMetrics;
|
|
31
|
+
endpoint = '/forge/entities/graphql';
|
|
32
|
+
constructor(getAppContextAri, apiClient, getMetrics) {
|
|
29
33
|
this.getAppContextAri = getAppContextAri;
|
|
30
34
|
this.apiClient = apiClient;
|
|
31
|
-
this.
|
|
35
|
+
this.getMetrics = getMetrics;
|
|
32
36
|
}
|
|
33
37
|
doGetAppContextAri() {
|
|
34
38
|
return typeof this.getAppContextAri === 'function' ? this.getAppContextAri() : this.getAppContextAri;
|
|
@@ -43,7 +47,7 @@ class GlobalStorage {
|
|
|
43
47
|
const requestBody = process.env.IS_CLEANUP_FUNCTION === 'true'
|
|
44
48
|
? gql_queries_1.UntypedQueries.listQueryForCleanup(this.doGetAppContextAri(), options)
|
|
45
49
|
: gql_queries_1.UntypedQueries.listQuery(this.doGetAppContextAri(), options);
|
|
46
|
-
const response = await this.query(requestBody);
|
|
50
|
+
const response = await this.wrapInMetric('untyped', 'query', false, async () => await this.query(requestBody));
|
|
47
51
|
const edges = process.env.IS_CLEANUP_FUNCTION === 'true'
|
|
48
52
|
? response.appStoredEntitiesForCleanup.edges
|
|
49
53
|
: response.appStoredEntities.edges;
|
|
@@ -56,7 +60,7 @@ class GlobalStorage {
|
|
|
56
60
|
}
|
|
57
61
|
async listCustomEntities(options) {
|
|
58
62
|
const requestBody = gql_queries_1.CustomEntityQueries.listQuery(this.doGetAppContextAri(), options);
|
|
59
|
-
const response = await this.query(requestBody);
|
|
63
|
+
const response = await this.wrapInMetric('typed', 'query', false, async () => await this.query(requestBody));
|
|
60
64
|
const edges = response.appStoredCustomEntities.edges;
|
|
61
65
|
const results = edges.map(({ node }) => node);
|
|
62
66
|
return {
|
|
@@ -66,40 +70,40 @@ class GlobalStorage {
|
|
|
66
70
|
}
|
|
67
71
|
async set(key, value) {
|
|
68
72
|
const requestBody = gql_queries_1.UntypedQueries.set(this.doGetAppContextAri(), key, value, false);
|
|
69
|
-
await this.mutation(requestBody, 'appStorage', 'setAppStoredEntity');
|
|
73
|
+
await this.wrapInMetric('untyped', 'set', false, async () => await this.mutation(requestBody, 'appStorage', 'setAppStoredEntity'));
|
|
70
74
|
}
|
|
71
75
|
async setSecret(key, value) {
|
|
72
76
|
const requestBody = gql_queries_1.UntypedQueries.set(this.doGetAppContextAri(), key, value, true);
|
|
73
|
-
await this.mutation(requestBody, 'appStorage', 'setAppStoredEntity');
|
|
77
|
+
await this.wrapInMetric('untyped', 'set', true, async () => await this.mutation(requestBody, 'appStorage', 'setAppStoredEntity'));
|
|
74
78
|
}
|
|
75
79
|
async delete(key) {
|
|
76
80
|
const requestBody = gql_queries_1.UntypedQueries.delete(this.doGetAppContextAri(), key, false);
|
|
77
|
-
await this.mutation(requestBody, 'appStorage', 'deleteAppStoredEntity');
|
|
81
|
+
await this.wrapInMetric('untyped', 'delete', false, async () => this.mutation(requestBody, 'appStorage', 'deleteAppStoredEntity'));
|
|
78
82
|
}
|
|
79
83
|
async deleteSecret(key) {
|
|
80
84
|
const requestBody = gql_queries_1.UntypedQueries.delete(this.doGetAppContextAri(), key, true);
|
|
81
|
-
await this.mutation(requestBody, 'appStorage', 'deleteAppStoredEntity');
|
|
85
|
+
await this.wrapInMetric('untyped', 'delete', true, async () => this.mutation(requestBody, 'appStorage', 'deleteAppStoredEntity'));
|
|
82
86
|
}
|
|
83
87
|
async getEntity(entityName, entityKey) {
|
|
84
88
|
return this.getEntityInternal(entityName, entityKey);
|
|
85
89
|
}
|
|
86
90
|
async setEntity(entityName, entityKey, value) {
|
|
87
91
|
const requestBody = gql_queries_1.CustomEntityQueries.set(this.doGetAppContextAri(), entityName, entityKey, value);
|
|
88
|
-
await this.mutation(requestBody, 'appStorageCustomEntity', 'setAppStoredCustomEntity');
|
|
92
|
+
await this.wrapInMetric('typed', 'set', false, async () => this.mutation(requestBody, 'appStorageCustomEntity', 'setAppStoredCustomEntity'));
|
|
89
93
|
}
|
|
90
94
|
async deleteEntity(entityName, entityKey) {
|
|
91
95
|
const requestBody = gql_queries_1.CustomEntityQueries.delete(this.doGetAppContextAri(), entityName, entityKey);
|
|
92
|
-
await this.mutation(requestBody, 'appStorageCustomEntity', 'deleteAppStoredCustomEntity');
|
|
96
|
+
await this.wrapInMetric('typed', 'delete', false, async () => await this.mutation(requestBody, 'appStorageCustomEntity', 'deleteAppStoredCustomEntity'));
|
|
93
97
|
}
|
|
94
98
|
async getInternal(key, encrypted) {
|
|
95
99
|
const requestBody = gql_queries_1.UntypedQueries.get(this.doGetAppContextAri(), key, encrypted);
|
|
96
|
-
const { appStoredEntity: { value } } = await this.query(requestBody);
|
|
97
|
-
return value
|
|
100
|
+
const { appStoredEntity: { value } } = await this.wrapInMetric('untyped', 'get', encrypted, async () => await this.query(requestBody));
|
|
101
|
+
return value ?? undefined;
|
|
98
102
|
}
|
|
99
103
|
async getEntityInternal(entityName, entityKey) {
|
|
100
104
|
const requestBody = gql_queries_1.CustomEntityQueries.get(this.doGetAppContextAri(), entityName, entityKey);
|
|
101
|
-
const { appStoredCustomEntity: { value } } = await this.query(requestBody);
|
|
102
|
-
return value
|
|
105
|
+
const { appStoredCustomEntity: { value } } = await this.wrapInMetric('typed', 'get', false, async () => await this.query(requestBody));
|
|
106
|
+
return value ?? undefined;
|
|
103
107
|
}
|
|
104
108
|
buildRequest(requestBody) {
|
|
105
109
|
return {
|
|
@@ -123,5 +127,39 @@ class GlobalStorage {
|
|
|
123
127
|
}
|
|
124
128
|
return response;
|
|
125
129
|
}
|
|
130
|
+
async wrapInMetric(store, operation, encrypted, fn) {
|
|
131
|
+
const metrics = this.getMetrics();
|
|
132
|
+
if (!metrics) {
|
|
133
|
+
return await fn();
|
|
134
|
+
}
|
|
135
|
+
const timer = metrics
|
|
136
|
+
.timing('forge.runtime.storage.operation.latency', { store, operation, encrypted: String(encrypted) })
|
|
137
|
+
.measure();
|
|
138
|
+
try {
|
|
139
|
+
const result = await fn();
|
|
140
|
+
timer.stop({ success: 'true' });
|
|
141
|
+
metrics
|
|
142
|
+
.counter('forge.runtime.storage.operation', {
|
|
143
|
+
store,
|
|
144
|
+
operation,
|
|
145
|
+
encrypted: String(encrypted),
|
|
146
|
+
success: 'true'
|
|
147
|
+
})
|
|
148
|
+
.incr();
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
timer.stop({ success: 'false' });
|
|
153
|
+
metrics
|
|
154
|
+
.counter('forge.runtime.storage.operation', {
|
|
155
|
+
store,
|
|
156
|
+
operation,
|
|
157
|
+
encrypted: String(encrypted),
|
|
158
|
+
success: 'false'
|
|
159
|
+
})
|
|
160
|
+
.incr();
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
126
164
|
}
|
|
127
165
|
exports.GlobalStorage = GlobalStorage;
|
package/out/gql-queries.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomEntityQueries = exports.UntypedQueries = void 0;
|
|
4
4
|
class UntypedQueries {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
UntypedQueries.get = (contextAri, key, encrypted) => ({
|
|
8
|
-
query: `
|
|
5
|
+
static get = (contextAri, key, encrypted) => ({
|
|
6
|
+
query: `
|
|
9
7
|
query forge_app_getApplicationStorageEntity($contextAri: ID!, $key: ID!, $encrypted: Boolean!) {
|
|
10
8
|
appStoredEntity(contextAri: $contextAri, key: $key, encrypted: $encrypted) {
|
|
11
9
|
key
|
|
@@ -13,14 +11,14 @@ UntypedQueries.get = (contextAri, key, encrypted) => ({
|
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
`,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
variables: {
|
|
15
|
+
contextAri,
|
|
16
|
+
key,
|
|
17
|
+
encrypted
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
static set = (contextAri, key, value, encrypted) => ({
|
|
21
|
+
query: `
|
|
24
22
|
mutation forge_app_setApplicationStorageEntity($input: SetAppStoredEntityMutationInput!) {
|
|
25
23
|
appStorage{
|
|
26
24
|
setAppStoredEntity(input: $input) {
|
|
@@ -37,17 +35,17 @@ UntypedQueries.set = (contextAri, key, value, encrypted) => ({
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
`,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
variables: {
|
|
39
|
+
input: {
|
|
40
|
+
contextAri,
|
|
41
|
+
key,
|
|
42
|
+
value,
|
|
43
|
+
encrypted
|
|
44
|
+
}
|
|
46
45
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
query: `
|
|
46
|
+
});
|
|
47
|
+
static delete = (contextAri, key, encrypted) => ({
|
|
48
|
+
query: `
|
|
51
49
|
mutation forge_app_deleteApplicationStorageEntity($input: DeleteAppStoredEntityMutationInput!) {
|
|
52
50
|
appStorage {
|
|
53
51
|
deleteAppStoredEntity(input: $input) {
|
|
@@ -64,17 +62,15 @@ UntypedQueries.delete = (contextAri, key, encrypted) => ({
|
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
`,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
variables: {
|
|
66
|
+
input: {
|
|
67
|
+
contextAri,
|
|
68
|
+
key,
|
|
69
|
+
encrypted
|
|
70
|
+
}
|
|
72
71
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
UntypedQueries.listQuery = (contextAri, options) => {
|
|
76
|
-
var _a, _b, _c;
|
|
77
|
-
return ({
|
|
72
|
+
});
|
|
73
|
+
static listQuery = (contextAri, options) => ({
|
|
78
74
|
query: `
|
|
79
75
|
query forge_app_getApplicationStorageEntities($contextAri: ID!, $where: [AppStoredEntityFilter!], $cursor: String, $limit: Int) {
|
|
80
76
|
appStoredEntities(contextAri: $contextAri, where: $where, after: $cursor, first: $limit) {
|
|
@@ -91,15 +87,12 @@ UntypedQueries.listQuery = (contextAri, options) => {
|
|
|
91
87
|
`,
|
|
92
88
|
variables: {
|
|
93
89
|
contextAri,
|
|
94
|
-
where:
|
|
95
|
-
cursor:
|
|
96
|
-
limit:
|
|
90
|
+
where: options.where ?? null,
|
|
91
|
+
cursor: options.cursor ?? null,
|
|
92
|
+
limit: options.limit ?? null
|
|
97
93
|
}
|
|
98
94
|
});
|
|
99
|
-
|
|
100
|
-
UntypedQueries.listQueryForCleanup = (contextAri, options) => {
|
|
101
|
-
var _a, _b, _c;
|
|
102
|
-
return ({
|
|
95
|
+
static listQueryForCleanup = (contextAri, options) => ({
|
|
103
96
|
query: `
|
|
104
97
|
query forge_app_getApplicationStorageEntitiesForCleanup($contextAri: ID!, $where: [AppStoredEntityFilter!], $cursor: String, $limit: Int) {
|
|
105
98
|
appStoredEntitiesForCleanup(contextAri: $contextAri, where: $where, after: $cursor, first: $limit) {
|
|
@@ -116,17 +109,16 @@ UntypedQueries.listQueryForCleanup = (contextAri, options) => {
|
|
|
116
109
|
`,
|
|
117
110
|
variables: {
|
|
118
111
|
contextAri,
|
|
119
|
-
where:
|
|
120
|
-
cursor:
|
|
121
|
-
limit:
|
|
112
|
+
where: options.where ?? null,
|
|
113
|
+
cursor: options.cursor ?? null,
|
|
114
|
+
limit: options.limit ?? null
|
|
122
115
|
}
|
|
123
116
|
});
|
|
124
|
-
};
|
|
125
|
-
class CustomEntityQueries {
|
|
126
117
|
}
|
|
127
|
-
exports.
|
|
128
|
-
CustomEntityQueries
|
|
129
|
-
|
|
118
|
+
exports.UntypedQueries = UntypedQueries;
|
|
119
|
+
class CustomEntityQueries {
|
|
120
|
+
static get = (contextAri, entityName, key) => ({
|
|
121
|
+
query: `
|
|
130
122
|
query forge_app_getApplicationStorageCustomEntity ($contextAri: ID!, $key: ID!, $entityName: String!) {
|
|
131
123
|
appStoredCustomEntity(contextAri: $contextAri, key: $key, entityName: $entityName) {
|
|
132
124
|
value
|
|
@@ -135,14 +127,14 @@ CustomEntityQueries.get = (contextAri, entityName, key) => ({
|
|
|
135
127
|
}
|
|
136
128
|
}
|
|
137
129
|
`,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
|
|
130
|
+
variables: {
|
|
131
|
+
contextAri,
|
|
132
|
+
entityName,
|
|
133
|
+
key
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
static set = (contextAri, entityName, key, value) => ({
|
|
137
|
+
query: `
|
|
146
138
|
mutation forge_app_setApplicationStorageCustomEntity($input: SetAppStoredCustomEntityMutationInput!) {
|
|
147
139
|
appStorageCustomEntity{
|
|
148
140
|
setAppStoredCustomEntity(input: $input) {
|
|
@@ -159,17 +151,17 @@ CustomEntityQueries.set = (contextAri, entityName, key, value) => ({
|
|
|
159
151
|
}
|
|
160
152
|
}
|
|
161
153
|
`,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
154
|
+
variables: {
|
|
155
|
+
input: {
|
|
156
|
+
contextAri,
|
|
157
|
+
entityName,
|
|
158
|
+
key,
|
|
159
|
+
value
|
|
160
|
+
}
|
|
168
161
|
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
query: `
|
|
162
|
+
});
|
|
163
|
+
static delete = (contextAri, entityName, key) => ({
|
|
164
|
+
query: `
|
|
173
165
|
mutation forge_app_deleteApplicationStorageCustomEntity($input: DeleteAppStoredCustomEntityMutationInput!) {
|
|
174
166
|
appStorageCustomEntity {
|
|
175
167
|
deleteAppStoredCustomEntity(input: $input) {
|
|
@@ -186,17 +178,17 @@ CustomEntityQueries.delete = (contextAri, entityName, key) => ({
|
|
|
186
178
|
}
|
|
187
179
|
}
|
|
188
180
|
`,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
181
|
+
variables: {
|
|
182
|
+
input: {
|
|
183
|
+
contextAri,
|
|
184
|
+
entityName,
|
|
185
|
+
key
|
|
186
|
+
}
|
|
194
187
|
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
query: `
|
|
188
|
+
});
|
|
189
|
+
static listQuery = (contextAri, options) => {
|
|
190
|
+
return {
|
|
191
|
+
query: `
|
|
200
192
|
query AppStorageCustomEntityQueries ($contextAri: ID!, $entityName: String!, $indexName: String!, $range: AppStoredCustomEntityRange, $filters: AppStoredCustomEntityFilters, $sort:SortOrder, $limit: Int, $cursor: String, $partition: [AppStoredCustomEntityFieldValue!]) {
|
|
201
193
|
appStoredCustomEntities(contextAri: $contextAri, entityName: $entityName, indexName: $indexName, range: $range, filters: $filters, sort:$sort, limit: $limit, cursor: $cursor, partition: $partition) {
|
|
202
194
|
edges {
|
|
@@ -215,12 +207,24 @@ CustomEntityQueries.listQuery = (contextAri, options) => {
|
|
|
215
207
|
}
|
|
216
208
|
}
|
|
217
209
|
`,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
210
|
+
variables: {
|
|
211
|
+
contextAri,
|
|
212
|
+
entityName: options.entityName,
|
|
213
|
+
indexName: options.indexName,
|
|
214
|
+
range: options.range,
|
|
215
|
+
...(options.filters && options.filters.length
|
|
216
|
+
? {
|
|
217
|
+
filters: {
|
|
218
|
+
[options.filterOperator || 'and']: options.filters
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
: {}),
|
|
222
|
+
...(options.partition ? { partition: options.partition } : {}),
|
|
223
|
+
...(options.sort ? { sort: options.sort } : {}),
|
|
224
|
+
...(options.cursor ? { cursor: options.cursor } : {}),
|
|
225
|
+
...(options.limit ? { limit: options.limit } : {})
|
|
223
226
|
}
|
|
224
|
-
|
|
227
|
+
};
|
|
225
228
|
};
|
|
226
|
-
}
|
|
229
|
+
}
|
|
230
|
+
exports.CustomEntityQueries = CustomEntityQueries;
|
package/out/query-api.js
CHANGED
|
@@ -2,20 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultQueryBuilder = void 0;
|
|
4
4
|
class DefaultQueryBuilder {
|
|
5
|
+
globalStorage;
|
|
6
|
+
queryOptions;
|
|
5
7
|
constructor(globalStorage, queryOptions = {}) {
|
|
6
8
|
this.globalStorage = globalStorage;
|
|
7
9
|
this.queryOptions = queryOptions;
|
|
8
10
|
}
|
|
9
11
|
where(field, where) {
|
|
10
|
-
return new DefaultQueryBuilder(this.globalStorage,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
return new DefaultQueryBuilder(this.globalStorage, {
|
|
13
|
+
...this.queryOptions,
|
|
14
|
+
where: [
|
|
15
|
+
{
|
|
16
|
+
field,
|
|
17
|
+
...where
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
});
|
|
13
21
|
}
|
|
14
22
|
cursor(cursor) {
|
|
15
|
-
return new DefaultQueryBuilder(this.globalStorage,
|
|
23
|
+
return new DefaultQueryBuilder(this.globalStorage, {
|
|
24
|
+
...this.queryOptions,
|
|
25
|
+
cursor
|
|
26
|
+
});
|
|
16
27
|
}
|
|
17
28
|
limit(limit) {
|
|
18
|
-
return new DefaultQueryBuilder(this.globalStorage,
|
|
29
|
+
return new DefaultQueryBuilder(this.globalStorage, {
|
|
30
|
+
...this.queryOptions,
|
|
31
|
+
limit
|
|
32
|
+
});
|
|
19
33
|
}
|
|
20
34
|
async getOne() {
|
|
21
35
|
const { results } = await this.limit(1).getMany();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-next.1",
|
|
4
4
|
"description": "Forge Storage methods",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "14.18.63",
|
|
19
19
|
"@types/node-fetch": "^2.6.11",
|
|
20
|
-
"node-fetch": "2.7.0"
|
|
20
|
+
"node-fetch": "2.7.0",
|
|
21
|
+
"@forge/util": "1.4.4",
|
|
22
|
+
"@atlassian/metrics-interface": "4.0.0"
|
|
21
23
|
}
|
|
22
|
-
}
|
|
24
|
+
}
|