@forge/storage 0.0.0-experimental-490cfcf → 0.0.0-experimental-85df747
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/out/__test__/global-storage.test.js +292 -11
- package/out/__test__/list-api.test.js +547 -5
- package/out/eap/conditions.d.ts +38 -2
- package/out/eap/conditions.d.ts.map +1 -1
- package/out/eap/conditions.js +98 -3
- package/out/entity-storage/index.d.ts +2 -0
- package/out/entity-storage/index.d.ts.map +1 -0
- package/out/entity-storage/index.js +5 -0
- package/out/entity-storage/query-api.d.ts +49 -0
- package/out/entity-storage/query-api.d.ts.map +1 -0
- package/out/entity-storage/query-api.js +122 -0
- package/out/entity-storage/storage-builder.d.ts +20 -0
- package/out/entity-storage/storage-builder.d.ts.map +1 -0
- package/out/entity-storage/storage-builder.js +23 -0
- package/out/errors.js +6 -4
- package/out/global-storage.d.ts +9 -3
- package/out/global-storage.d.ts.map +1 -1
- package/out/global-storage.js +45 -14
- package/out/gql-queries.d.ts +106 -0
- package/out/gql-queries.d.ts.map +1 -0
- package/out/gql-queries.js +244 -0
- package/out/index.d.ts +6 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +10 -3
- package/out/query-api.d.ts +1 -1
- package/out/query-api.d.ts.map +1 -1
- package/out/query-interfaces.d.ts +121 -0
- package/out/query-interfaces.d.ts.map +1 -0
- package/out/query-interfaces.js +8 -0
- package/out/storage-adapter.d.ts +26 -13
- package/out/storage-adapter.d.ts.map +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -114
- package/out/queries.d.ts +0 -69
- package/out/queries.d.ts.map +0 -1
- package/out/queries.js +0 -119
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const errors_1 = require("../errors");
|
|
4
4
|
const global_storage_1 = require("../global-storage");
|
|
5
|
-
const
|
|
5
|
+
const gql_queries_1 = require("../gql-queries");
|
|
6
6
|
const contextAri = 'app-ari';
|
|
7
7
|
const getStorage = (apiClientMock) => new global_storage_1.GlobalStorage(() => contextAri, apiClientMock);
|
|
8
8
|
const getApiClientMock = (response, statusCode = 200) => {
|
|
@@ -25,6 +25,28 @@ const INVALID_CURSOR_ERROR = {
|
|
|
25
25
|
errorType: 'INVALID_CURSOR'
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
const schemas = [
|
|
29
|
+
{
|
|
30
|
+
name: 'cars',
|
|
31
|
+
attributes: {
|
|
32
|
+
model: { type: 'string' },
|
|
33
|
+
make: { type: 'string' },
|
|
34
|
+
year: { type: 'float' }
|
|
35
|
+
},
|
|
36
|
+
indexes: [
|
|
37
|
+
{
|
|
38
|
+
name: 'by-year',
|
|
39
|
+
partition: ['year'],
|
|
40
|
+
range: ['model']
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'by-make',
|
|
44
|
+
partition: ['make'],
|
|
45
|
+
range: ['model']
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
];
|
|
28
50
|
describe('GlobalStorage', () => {
|
|
29
51
|
function verifyApiClientCalledWith(apiClientMock, variables, query) {
|
|
30
52
|
expect(apiClientMock).toHaveBeenCalledWith('/forge/entities/graphql', expect.objectContaining({
|
|
@@ -128,13 +150,6 @@ describe('GlobalStorage', () => {
|
|
|
128
150
|
expect(apiClientMock).toHaveBeenCalled();
|
|
129
151
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
130
152
|
});
|
|
131
|
-
it('should throw an error if the storage API returns a non 200 status code', async () => {
|
|
132
|
-
const apiClientMock = getApiClientMock(undefined, 400);
|
|
133
|
-
const globalStorage = getStorage(apiClientMock);
|
|
134
|
-
const response = globalStorage.get('testKey');
|
|
135
|
-
expect(apiClientMock).toHaveBeenCalled();
|
|
136
|
-
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
137
|
-
});
|
|
138
153
|
it('should throw an error if the response is not a valid JSON', async () => {
|
|
139
154
|
const apiClientMock = getApiClientMockInvalidJson('test', 200);
|
|
140
155
|
const globalStorage = getStorage(apiClientMock);
|
|
@@ -319,6 +334,211 @@ describe('GlobalStorage', () => {
|
|
|
319
334
|
});
|
|
320
335
|
});
|
|
321
336
|
});
|
|
337
|
+
describe('getEntity', () => {
|
|
338
|
+
it('should call the storage API, passing the provided entity name and entity key and returning the stored value', async () => {
|
|
339
|
+
const apiClientMock = getApiClientMock({
|
|
340
|
+
data: {
|
|
341
|
+
appStoredCustomEntity: {
|
|
342
|
+
value: 'testValue'
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const globalStorage = getStorage(apiClientMock);
|
|
347
|
+
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
348
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
349
|
+
contextAri,
|
|
350
|
+
entityName: 'testEntityName',
|
|
351
|
+
key: 'testEntityKey'
|
|
352
|
+
});
|
|
353
|
+
expect(returnedValue).toEqual('testValue');
|
|
354
|
+
});
|
|
355
|
+
it('should call the storage API, passing the provided entity key and returning undefined if the key doesnt exist', async () => {
|
|
356
|
+
const apiClientMock = getApiClientMock({
|
|
357
|
+
data: {
|
|
358
|
+
appStoredCustomEntity: {
|
|
359
|
+
value: null
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
const globalStorage = getStorage(apiClientMock);
|
|
364
|
+
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
365
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
366
|
+
contextAri,
|
|
367
|
+
entityName: 'testEntityName',
|
|
368
|
+
key: 'testEntityKey'
|
|
369
|
+
});
|
|
370
|
+
expect(returnedValue).toEqual(undefined);
|
|
371
|
+
});
|
|
372
|
+
it('should call the storage API, passing the provided key and returning the stored falsey value 0', async () => {
|
|
373
|
+
const apiClientMock = getApiClientMock({
|
|
374
|
+
data: {
|
|
375
|
+
appStoredCustomEntity: {
|
|
376
|
+
value: 0
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
const globalStorage = getStorage(apiClientMock);
|
|
381
|
+
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
382
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
383
|
+
contextAri,
|
|
384
|
+
entityName: 'testEntityName',
|
|
385
|
+
key: 'testEntityKey'
|
|
386
|
+
});
|
|
387
|
+
expect(returnedValue).toEqual(0);
|
|
388
|
+
});
|
|
389
|
+
it('should call the storage API, passing the provided key and returning the stored empty string', async () => {
|
|
390
|
+
const apiClientMock = getApiClientMock({
|
|
391
|
+
data: {
|
|
392
|
+
appStoredCustomEntity: {
|
|
393
|
+
value: ''
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
const globalStorage = getStorage(apiClientMock);
|
|
398
|
+
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
399
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
400
|
+
contextAri,
|
|
401
|
+
entityName: 'testEntityName',
|
|
402
|
+
key: 'testEntityKey'
|
|
403
|
+
});
|
|
404
|
+
expect(returnedValue).toEqual('');
|
|
405
|
+
});
|
|
406
|
+
it('should throw an error with the returned status for non-200 status codes', async () => {
|
|
407
|
+
const apiClientMock = getApiClientMock(undefined, 400);
|
|
408
|
+
const globalStorage = getStorage(apiClientMock);
|
|
409
|
+
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
410
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
411
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
412
|
+
});
|
|
413
|
+
it('should throw an error with the returned error message for failed responses', async () => {
|
|
414
|
+
const apiClientMock = getApiClientMock({
|
|
415
|
+
errors: [INVALID_CURSOR_ERROR]
|
|
416
|
+
}, 200);
|
|
417
|
+
const globalStorage = getStorage(apiClientMock);
|
|
418
|
+
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
419
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
420
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
421
|
+
});
|
|
422
|
+
it('should throw an error if the response is not a valid JSON', async () => {
|
|
423
|
+
const apiClientMock = getApiClientMockInvalidJson('test', 200);
|
|
424
|
+
const globalStorage = getStorage(apiClientMock);
|
|
425
|
+
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
426
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
427
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forUnexpected('Response text was not a valid JSON: test'));
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
describe('setEntity', () => {
|
|
431
|
+
it('should call the storage API, passing the provided entity name, entity key and value', async () => {
|
|
432
|
+
const apiClientMock = getApiClientMock({
|
|
433
|
+
data: {
|
|
434
|
+
appStorageCustomEntity: {
|
|
435
|
+
setAppStoredCustomEntity: {
|
|
436
|
+
success: true
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
const globalStorage = getStorage(apiClientMock);
|
|
442
|
+
await globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
|
|
443
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
444
|
+
input: {
|
|
445
|
+
contextAri,
|
|
446
|
+
entityName: 'testEntityName',
|
|
447
|
+
key: 'testEntityKey',
|
|
448
|
+
value: 'testValue'
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
it('should throw an error if the storage API returns successful = false', async () => {
|
|
453
|
+
const apiClientMock = getApiClientMock({
|
|
454
|
+
data: {
|
|
455
|
+
appStorageCustomEntity: {
|
|
456
|
+
setAppStoredCustomEntity: {
|
|
457
|
+
success: false,
|
|
458
|
+
errors: [INVALID_CURSOR_ERROR]
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
const globalStorage = getStorage(apiClientMock);
|
|
464
|
+
const response = globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
|
|
465
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
466
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('INVALID_CURSOR', 'error message'));
|
|
467
|
+
});
|
|
468
|
+
it('should throw an error if the storage API returns a non 200 status code', async () => {
|
|
469
|
+
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
470
|
+
const globalStorage = getStorage(apiClientMock);
|
|
471
|
+
const response = globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
|
|
472
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
473
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
474
|
+
});
|
|
475
|
+
it('should throw a 500 error if success=false but no errors were returned', async () => {
|
|
476
|
+
const apiClientMock = getApiClientMock({
|
|
477
|
+
data: {
|
|
478
|
+
appStorageCustomEntity: {
|
|
479
|
+
setAppStoredCustomEntity: {
|
|
480
|
+
success: false
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
const globalStorage = getStorage(apiClientMock);
|
|
486
|
+
await expect(globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue')).rejects.toThrow(errors_1.APIError.forStatus(500));
|
|
487
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
488
|
+
input: {
|
|
489
|
+
contextAri,
|
|
490
|
+
entityName: 'testEntityName',
|
|
491
|
+
key: 'testEntityKey',
|
|
492
|
+
value: 'testValue'
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
describe('deleteEntity', () => {
|
|
498
|
+
it('should call the storage API, passing the provided entity name and key', async () => {
|
|
499
|
+
const apiClientMock = getApiClientMock({
|
|
500
|
+
data: {
|
|
501
|
+
appStorageCustomEntity: {
|
|
502
|
+
deleteAppStoredCustomEntity: {
|
|
503
|
+
success: true
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
const globalStorage = getStorage(apiClientMock);
|
|
509
|
+
await globalStorage.deleteEntity('testEntityName', 'testEntityKey');
|
|
510
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
511
|
+
input: {
|
|
512
|
+
contextAri,
|
|
513
|
+
entityName: 'testEntityName',
|
|
514
|
+
key: 'testEntityKey'
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
it('should throw an error if the storage API returns successful = false', async () => {
|
|
519
|
+
const apiClientMock = getApiClientMock({
|
|
520
|
+
data: {
|
|
521
|
+
appStorageCustomEntity: {
|
|
522
|
+
deleteAppStoredCustomEntity: {
|
|
523
|
+
success: false,
|
|
524
|
+
errors: [INVALID_CURSOR_ERROR]
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
const globalStorage = getStorage(apiClientMock);
|
|
530
|
+
const response = globalStorage.deleteEntity('testEntityKey', 'testEntityKey');
|
|
531
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
532
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
533
|
+
});
|
|
534
|
+
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
|
|
535
|
+
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
536
|
+
const globalStorage = getStorage(apiClientMock);
|
|
537
|
+
const response = globalStorage.deleteEntity('testEntityKey', 'testEntityKey');
|
|
538
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
539
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
540
|
+
});
|
|
541
|
+
});
|
|
322
542
|
describe('list', () => {
|
|
323
543
|
it('should call the storage API with the provided parameters', async () => {
|
|
324
544
|
const apiClientMock = getApiClientMock({
|
|
@@ -347,7 +567,7 @@ describe('GlobalStorage', () => {
|
|
|
347
567
|
where,
|
|
348
568
|
cursor,
|
|
349
569
|
limit
|
|
350
|
-
},
|
|
570
|
+
}, gql_queries_1.UntypedQueries.listQuery(contextAri, {}).query);
|
|
351
571
|
expect(response).toEqual(expect.objectContaining({
|
|
352
572
|
results: [
|
|
353
573
|
{ key: 'key1', value: 'testValue' },
|
|
@@ -384,7 +604,7 @@ describe('GlobalStorage', () => {
|
|
|
384
604
|
where,
|
|
385
605
|
cursor,
|
|
386
606
|
limit
|
|
387
|
-
},
|
|
607
|
+
}, gql_queries_1.UntypedQueries.listQueryForCleanup(contextAri, {}).query);
|
|
388
608
|
expect(response).toEqual(expect.objectContaining({
|
|
389
609
|
results: [
|
|
390
610
|
{ key: 'key1', value: 'testValue' },
|
|
@@ -409,7 +629,7 @@ describe('GlobalStorage', () => {
|
|
|
409
629
|
where: null,
|
|
410
630
|
cursor: null,
|
|
411
631
|
limit: null
|
|
412
|
-
},
|
|
632
|
+
}, gql_queries_1.UntypedQueries.listQuery(contextAri, {}).query);
|
|
413
633
|
});
|
|
414
634
|
it('should handle an empty result set', async () => {
|
|
415
635
|
const apiClientMock = getApiClientMock({
|
|
@@ -450,4 +670,65 @@ describe('GlobalStorage', () => {
|
|
|
450
670
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
451
671
|
});
|
|
452
672
|
});
|
|
673
|
+
describe('upsertCustomEntity', () => {
|
|
674
|
+
it('should call the storage API, passing the provided entities', async () => {
|
|
675
|
+
const apiClientMock = getApiClientMock({
|
|
676
|
+
data: {
|
|
677
|
+
customSchema: {
|
|
678
|
+
createCustomSchema: {
|
|
679
|
+
success: true
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
const globalStorage = getStorage(apiClientMock);
|
|
685
|
+
await globalStorage.upsertCustomEntities(schemas);
|
|
686
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
687
|
+
input: {
|
|
688
|
+
schemas
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
it('should throw an error if the storage API returns successful = false', async () => {
|
|
693
|
+
const apiClientMock = getApiClientMock({
|
|
694
|
+
data: {
|
|
695
|
+
customSchema: {
|
|
696
|
+
createCustomSchema: {
|
|
697
|
+
success: false,
|
|
698
|
+
errors: [INVALID_CURSOR_ERROR]
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
const globalStorage = getStorage(apiClientMock);
|
|
704
|
+
const response = globalStorage.upsertCustomEntities(schemas);
|
|
705
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
706
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('INVALID_CURSOR', 'error message'));
|
|
707
|
+
});
|
|
708
|
+
it('should throw an error if the storage API returns a non 200 status code', async () => {
|
|
709
|
+
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
710
|
+
const globalStorage = getStorage(apiClientMock);
|
|
711
|
+
const response = globalStorage.upsertCustomEntities(schemas);
|
|
712
|
+
expect(apiClientMock).toHaveBeenCalled();
|
|
713
|
+
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
714
|
+
});
|
|
715
|
+
it('should throw a 500 error if success=false but no errors were returned', async () => {
|
|
716
|
+
const apiClientMock = getApiClientMock({
|
|
717
|
+
data: {
|
|
718
|
+
customSchema: {
|
|
719
|
+
createCustomSchema: {
|
|
720
|
+
success: false
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
const globalStorage = getStorage(apiClientMock);
|
|
726
|
+
await expect(globalStorage.upsertCustomEntities(schemas)).rejects.toThrow(errors_1.APIError.forStatus(500));
|
|
727
|
+
verifyApiClientCalledWith(apiClientMock, {
|
|
728
|
+
input: {
|
|
729
|
+
schemas
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
});
|
|
453
734
|
});
|