@forge/storage 1.5.15-experimental-7fc11d3 → 1.5.15-experimental-95c622a

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.
@@ -263,7 +263,7 @@ describe('GlobalStorage', () => {
263
263
  }
264
264
  });
265
265
  const globalStorage = getStorage(apiClientMock);
266
- await globalStorage.bulkSet([
266
+ const response = await globalStorage.bulkSet([
267
267
  {
268
268
  key: 'testKey',
269
269
  value: 'testValue'
@@ -281,6 +281,8 @@ describe('GlobalStorage', () => {
281
281
  encrypted: false
282
282
  }
283
283
  });
284
+ expect(response).toHaveProperty('savedKeys', ['testKey']);
285
+ expect(response).toHaveProperty('failedKeys', []);
284
286
  });
285
287
  it('should throw an error if the storage API returns successful = false', async () => {
286
288
  const apiClientMock = getApiClientMock({
@@ -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 = Object.assign({}, queryOptions);
10
+ this.queryOptions = {
11
+ ...queryOptions
12
+ };
9
13
  }
10
14
  clone(overrides) {
11
- return new (Object.getPrototypeOf(this).constructor)(this.globalStorage, Object.assign(Object.assign({}, this.queryOptions), overrides));
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: Object.assign({}, condition)
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 === null || results === void 0 ? void 0 : results[0];
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 = Object.assign({}, this.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 = Object.assign({}, queryOptions);
67
+ this.queryOptions = {
68
+ ...queryOptions
69
+ };
57
70
  }
58
71
  andFilter(field, condition) {
59
- var _a;
60
- const newQueryOptions = Object.assign({}, this.queryOptions);
61
- newQueryOptions.filters = [...((_a = this.queryOptions.filters) !== null && _a !== void 0 ? _a : []), Object.assign({ property: field }, condition)];
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 = Object.assign({}, queryOptions);
87
+ this.queryOptions = {
88
+ ...queryOptions
89
+ };
72
90
  }
73
91
  orFilter(field, condition) {
74
- var _a;
75
- const newQueryOptions = Object.assign({}, this.queryOptions);
76
- newQueryOptions.filters = [...((_a = this.queryOptions.filters) !== null && _a !== void 0 ? _a : []), Object.assign({ property: field }, condition)];
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 = Object.assign({}, 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 = Object.assign({}, queryOptions);
124
+ this.queryOptions = {
125
+ ...queryOptions
126
+ };
100
127
  }
101
128
  index(name, indexOptions) {
102
- const indexProperties = indexOptions ? Object.assign({ indexName: name }, indexOptions) : { indexName: name };
103
- return new CustomEntityFilterQueryBuilder(this.globalStorage, Object.assign(Object.assign({}, this.queryOptions), indexProperties));
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 = Object.assign({}, queryOptions);
143
+ this.queryOptions = {
144
+ ...queryOptions
145
+ };
112
146
  }
113
147
  entity(name) {
114
- return new CustomEntityIndexBuilder(this.globalStorage, Object.assign(Object.assign({}, this.queryOptions), { entityName: name }));
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 !== null && message !== void 0 ? message : code;
5
+ return message ?? code;
6
6
  };
7
7
  exports.getErrorMessageFromCode = getErrorMessageFromCode;
8
8
  const getErrorMessage = (statusCode) => {
@@ -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;AAE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AK,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,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAYjD,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"}
@@ -25,10 +25,12 @@ async function getResponseBody(response) {
25
25
  return responseBody.data;
26
26
  }
27
27
  class GlobalStorage {
28
+ getAppContextAri;
29
+ apiClient;
30
+ endpoint = '/forge/entities/graphql';
28
31
  constructor(getAppContextAri, apiClient) {
29
32
  this.getAppContextAri = getAppContextAri;
30
33
  this.apiClient = apiClient;
31
- this.endpoint = '/forge/entities/graphql';
32
34
  }
33
35
  doGetAppContextAri() {
34
36
  return typeof this.getAppContextAri === 'function' ? this.getAppContextAri() : this.getAppContextAri;
@@ -74,10 +76,9 @@ class GlobalStorage {
74
76
  }
75
77
  async bulkSet(items) {
76
78
  const requestBody = gql_queries_1.UntypedQueries.bulkSet(this.doGetAppContextAri(), items, false);
77
- const response = await this.mutation(requestBody, 'appStorage', 'setAppStoredEntities');
78
- const parsedResponse = await getResponseBody(response);
79
- const failedKeys = parsedResponse.appStorage.setAppStoredEntities.failedKeys;
80
- const savedKeys = parsedResponse.appStorage.setAppStoredEntities.savedKeys;
79
+ const response = await this.mutation(requestBody, 'appStorage', 'setAppStoredEntities', true);
80
+ const failedKeys = response.failedKeys;
81
+ const savedKeys = response.savedKeys;
81
82
  return {
82
83
  savedKeys,
83
84
  failedKeys
@@ -105,12 +106,12 @@ class GlobalStorage {
105
106
  async getInternal(key, encrypted) {
106
107
  const requestBody = gql_queries_1.UntypedQueries.get(this.doGetAppContextAri(), key, encrypted);
107
108
  const { appStoredEntity: { value } } = await this.query(requestBody);
108
- return value !== null && value !== void 0 ? value : undefined;
109
+ return value ?? undefined;
109
110
  }
110
111
  async getEntityInternal(entityName, entityKey) {
111
112
  const requestBody = gql_queries_1.CustomEntityQueries.get(this.doGetAppContextAri(), entityName, entityKey);
112
113
  const { appStoredCustomEntity: { value } } = await this.query(requestBody);
113
- return value !== null && value !== void 0 ? value : undefined;
114
+ return value ?? undefined;
114
115
  }
115
116
  buildRequest(requestBody) {
116
117
  return {
@@ -125,13 +126,16 @@ class GlobalStorage {
125
126
  const response = await this.apiClient(this.endpoint, this.buildRequest(body));
126
127
  return await getResponseBody(response);
127
128
  }
128
- async mutation(body, namespace, mutationMethod) {
129
+ async mutation(body, namespace, mutationMethod, returnResponseBody) {
129
130
  const response = await this.apiClient(this.endpoint, this.buildRequest(body));
130
- const { [namespace]: { [mutationMethod]: { success, errors } } } = await getResponseBody(response);
131
- assertNoErrors(errors);
132
- if (!success) {
131
+ const { [namespace]: { [mutationMethod]: mutationResponse } } = await getResponseBody(response);
132
+ assertNoErrors(mutationResponse.errors);
133
+ if (!mutationResponse.success) {
133
134
  throw errors_1.APIError.forStatus(500);
134
135
  }
136
+ if (returnResponseBody) {
137
+ return mutationResponse;
138
+ }
135
139
  return response;
136
140
  }
137
141
  }
@@ -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
- exports.UntypedQueries = UntypedQueries;
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
- variables: {
17
- contextAri,
18
- key,
19
- encrypted
20
- }
21
- });
22
- UntypedQueries.set = (contextAri, key, value, encrypted) => ({
23
- query: `
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
- variables: {
41
- input: {
42
- contextAri,
43
- key,
44
- value,
45
- encrypted
38
+ variables: {
39
+ input: {
40
+ contextAri,
41
+ key,
42
+ value,
43
+ encrypted
44
+ }
46
45
  }
47
- }
48
- });
49
- UntypedQueries.delete = (contextAri, key, encrypted) => ({
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
- variables: {
68
- input: {
69
- contextAri,
70
- key,
71
- encrypted
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: (_a = options.where) !== null && _a !== void 0 ? _a : null,
95
- cursor: (_b = options.cursor) !== null && _b !== void 0 ? _b : null,
96
- limit: (_c = options.limit) !== null && _c !== void 0 ? _c : null
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,14 +109,13 @@ UntypedQueries.listQueryForCleanup = (contextAri, options) => {
116
109
  `,
117
110
  variables: {
118
111
  contextAri,
119
- where: (_a = options.where) !== null && _a !== void 0 ? _a : null,
120
- cursor: (_b = options.cursor) !== null && _b !== void 0 ? _b : null,
121
- limit: (_c = options.limit) !== null && _c !== void 0 ? _c : null
112
+ where: options.where ?? null,
113
+ cursor: options.cursor ?? null,
114
+ limit: options.limit ?? null
122
115
  }
123
116
  });
124
- };
125
- UntypedQueries.bulkSet = (contextAri, values, encrypted) => ({
126
- query: `
117
+ static bulkSet = (contextAri, values, encrypted) => ({
118
+ query: `
127
119
  mutation forge_app_setApplicationStorageEntities($input: SetAppStoredEntitiesMutationInput!) {
128
120
  appStorage{
129
121
  setAppStoredEntities(input: $input) {
@@ -141,19 +133,19 @@ UntypedQueries.bulkSet = (contextAri, values, encrypted) => ({
141
133
  }
142
134
  }
143
135
  `,
144
- variables: {
145
- input: {
146
- contextAri,
147
- entities: values,
148
- encrypted
136
+ variables: {
137
+ input: {
138
+ contextAri,
139
+ entities: values,
140
+ encrypted
141
+ }
149
142
  }
150
- }
151
- });
152
- class CustomEntityQueries {
143
+ });
153
144
  }
154
- exports.CustomEntityQueries = CustomEntityQueries;
155
- CustomEntityQueries.get = (contextAri, entityName, key) => ({
156
- query: `
145
+ exports.UntypedQueries = UntypedQueries;
146
+ class CustomEntityQueries {
147
+ static get = (contextAri, entityName, key) => ({
148
+ query: `
157
149
  query forge_app_getApplicationStorageCustomEntity ($contextAri: ID!, $key: ID!, $entityName: String!) {
158
150
  appStoredCustomEntity(contextAri: $contextAri, key: $key, entityName: $entityName) {
159
151
  value
@@ -162,14 +154,14 @@ CustomEntityQueries.get = (contextAri, entityName, key) => ({
162
154
  }
163
155
  }
164
156
  `,
165
- variables: {
166
- contextAri,
167
- entityName,
168
- key
169
- }
170
- });
171
- CustomEntityQueries.set = (contextAri, entityName, key, value) => ({
172
- query: `
157
+ variables: {
158
+ contextAri,
159
+ entityName,
160
+ key
161
+ }
162
+ });
163
+ static set = (contextAri, entityName, key, value) => ({
164
+ query: `
173
165
  mutation forge_app_setApplicationStorageCustomEntity($input: SetAppStoredCustomEntityMutationInput!) {
174
166
  appStorageCustomEntity{
175
167
  setAppStoredCustomEntity(input: $input) {
@@ -186,17 +178,17 @@ CustomEntityQueries.set = (contextAri, entityName, key, value) => ({
186
178
  }
187
179
  }
188
180
  `,
189
- variables: {
190
- input: {
191
- contextAri,
192
- entityName,
193
- key,
194
- value
181
+ variables: {
182
+ input: {
183
+ contextAri,
184
+ entityName,
185
+ key,
186
+ value
187
+ }
195
188
  }
196
- }
197
- });
198
- CustomEntityQueries.delete = (contextAri, entityName, key) => ({
199
- query: `
189
+ });
190
+ static delete = (contextAri, entityName, key) => ({
191
+ query: `
200
192
  mutation forge_app_deleteApplicationStorageCustomEntity($input: DeleteAppStoredCustomEntityMutationInput!) {
201
193
  appStorageCustomEntity {
202
194
  deleteAppStoredCustomEntity(input: $input) {
@@ -213,17 +205,17 @@ CustomEntityQueries.delete = (contextAri, entityName, key) => ({
213
205
  }
214
206
  }
215
207
  `,
216
- variables: {
217
- input: {
218
- contextAri,
219
- entityName,
220
- key
208
+ variables: {
209
+ input: {
210
+ contextAri,
211
+ entityName,
212
+ key
213
+ }
221
214
  }
222
- }
223
- });
224
- CustomEntityQueries.listQuery = (contextAri, options) => {
225
- return {
226
- query: `
215
+ });
216
+ static listQuery = (contextAri, options) => {
217
+ return {
218
+ query: `
227
219
  query AppStorageCustomEntityQueries ($contextAri: ID!, $entityName: String!, $indexName: String!, $range: AppStoredCustomEntityRange, $filters: AppStoredCustomEntityFilters, $sort:SortOrder, $limit: Int, $cursor: String, $partition: [AppStoredCustomEntityFieldValue!]) {
228
220
  appStoredCustomEntities(contextAri: $contextAri, entityName: $entityName, indexName: $indexName, range: $range, filters: $filters, sort:$sort, limit: $limit, cursor: $cursor, partition: $partition) {
229
221
  edges {
@@ -242,12 +234,24 @@ CustomEntityQueries.listQuery = (contextAri, options) => {
242
234
  }
243
235
  }
244
236
  `,
245
- variables: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ contextAri, entityName: options.entityName, indexName: options.indexName, range: options.range }, (options.filters && options.filters.length
246
- ? {
247
- filters: {
248
- [options.filterOperator || 'and']: options.filters
249
- }
237
+ variables: {
238
+ contextAri,
239
+ entityName: options.entityName,
240
+ indexName: options.indexName,
241
+ range: options.range,
242
+ ...(options.filters && options.filters.length
243
+ ? {
244
+ filters: {
245
+ [options.filterOperator || 'and']: options.filters
246
+ }
247
+ }
248
+ : {}),
249
+ ...(options.partition ? { partition: options.partition } : {}),
250
+ ...(options.sort ? { sort: options.sort } : {}),
251
+ ...(options.cursor ? { cursor: options.cursor } : {}),
252
+ ...(options.limit ? { limit: options.limit } : {})
250
253
  }
251
- : {})), (options.partition ? { partition: options.partition } : {})), (options.sort ? { sort: options.sort } : {})), (options.cursor ? { cursor: options.cursor } : {})), (options.limit ? { limit: options.limit } : {}))
254
+ };
252
255
  };
253
- };
256
+ }
257
+ 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, Object.assign(Object.assign({}, this.queryOptions), { where: [
11
- Object.assign({ field }, where)
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, Object.assign(Object.assign({}, this.queryOptions), { cursor }));
23
+ return new DefaultQueryBuilder(this.globalStorage, {
24
+ ...this.queryOptions,
25
+ cursor
26
+ });
16
27
  }
17
28
  limit(limit) {
18
- return new DefaultQueryBuilder(this.globalStorage, Object.assign(Object.assign({}, this.queryOptions), { limit }));
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.5.15-experimental-7fc11d3",
3
+ "version": "1.5.15-experimental-95c622a",
4
4
  "description": "Forge Storage methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",