@cratis/arc 18.4.3 → 18.5.0

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.
Files changed (94) hide show
  1. package/commands/for_Command/given/a_command.ts +4 -5
  2. package/commands/for_Command/when_executing/with_custom_http_headers.ts +4 -1
  3. package/commands/for_Command/when_executing/with_origin_and_api_base_path.ts +5 -2
  4. package/commands/for_Command/when_executing/with_route_parameters.ts +4 -2
  5. package/dist/cjs/helpers/fetchHelper.d.ts +7 -0
  6. package/dist/cjs/helpers/fetchHelper.d.ts.map +1 -0
  7. package/dist/cjs/identity/IIdentityProvider.d.ts +2 -1
  8. package/dist/cjs/identity/IIdentityProvider.d.ts.map +1 -1
  9. package/dist/cjs/identity/IIdentityProvider.js.map +1 -1
  10. package/dist/cjs/identity/IdentityProvider.d.ts +4 -3
  11. package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
  12. package/dist/cjs/identity/IdentityProvider.js +12 -9
  13. package/dist/cjs/identity/IdentityProvider.js.map +1 -1
  14. package/dist/cjs/queries/IObservableQueryConnection.d.ts +2 -0
  15. package/dist/cjs/queries/IObservableQueryConnection.d.ts.map +1 -1
  16. package/dist/cjs/queries/NullObservableQueryConnection.d.ts +2 -0
  17. package/dist/cjs/queries/NullObservableQueryConnection.d.ts.map +1 -1
  18. package/dist/cjs/queries/NullObservableQueryConnection.js +6 -0
  19. package/dist/cjs/queries/NullObservableQueryConnection.js.map +1 -1
  20. package/dist/cjs/queries/ObservableQueryConnection.d.ts +14 -1
  21. package/dist/cjs/queries/ObservableQueryConnection.d.ts.map +1 -1
  22. package/dist/cjs/queries/ObservableQueryConnection.js +73 -2
  23. package/dist/cjs/queries/ObservableQueryConnection.js.map +1 -1
  24. package/dist/cjs/queries/WebSocketMessage.d.ts +11 -0
  25. package/dist/cjs/queries/WebSocketMessage.d.ts.map +1 -0
  26. package/dist/cjs/queries/WebSocketMessage.js +9 -0
  27. package/dist/cjs/queries/WebSocketMessage.js.map +1 -0
  28. package/dist/cjs/queries/index.d.ts +1 -0
  29. package/dist/cjs/queries/index.d.ts.map +1 -1
  30. package/dist/cjs/queries/index.js +5 -0
  31. package/dist/cjs/queries/index.js.map +1 -1
  32. package/dist/esm/helpers/fetchHelper.d.ts +7 -0
  33. package/dist/esm/helpers/fetchHelper.d.ts.map +1 -0
  34. package/dist/esm/helpers/fetchHelper.js +22 -0
  35. package/dist/esm/helpers/fetchHelper.js.map +1 -0
  36. package/dist/esm/identity/IIdentityProvider.d.ts +2 -1
  37. package/dist/esm/identity/IIdentityProvider.d.ts.map +1 -1
  38. package/dist/esm/identity/IIdentityProvider.js.map +1 -1
  39. package/dist/esm/identity/IdentityProvider.d.ts +4 -3
  40. package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
  41. package/dist/esm/identity/IdentityProvider.js +12 -9
  42. package/dist/esm/identity/IdentityProvider.js.map +1 -1
  43. package/dist/esm/queries/IObservableQueryConnection.d.ts +2 -0
  44. package/dist/esm/queries/IObservableQueryConnection.d.ts.map +1 -1
  45. package/dist/esm/queries/NullObservableQueryConnection.d.ts +2 -0
  46. package/dist/esm/queries/NullObservableQueryConnection.d.ts.map +1 -1
  47. package/dist/esm/queries/NullObservableQueryConnection.js +6 -0
  48. package/dist/esm/queries/NullObservableQueryConnection.js.map +1 -1
  49. package/dist/esm/queries/ObservableQueryConnection.d.ts +14 -1
  50. package/dist/esm/queries/ObservableQueryConnection.d.ts.map +1 -1
  51. package/dist/esm/queries/ObservableQueryConnection.js +73 -2
  52. package/dist/esm/queries/ObservableQueryConnection.js.map +1 -1
  53. package/dist/esm/queries/WebSocketMessage.d.ts +11 -0
  54. package/dist/esm/queries/WebSocketMessage.d.ts.map +1 -0
  55. package/dist/esm/queries/WebSocketMessage.js +9 -0
  56. package/dist/esm/queries/WebSocketMessage.js.map +1 -0
  57. package/dist/esm/queries/index.d.ts +1 -0
  58. package/dist/esm/queries/index.d.ts.map +1 -1
  59. package/dist/esm/queries/index.js +1 -0
  60. package/dist/esm/queries/index.js.map +1 -1
  61. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  62. package/helpers/fetchHelper.ts +30 -0
  63. package/identity/IIdentityProvider.ts +4 -1
  64. package/identity/IdentityProvider.ts +14 -9
  65. package/identity/for_IdentityProvider/given/an_identity_provider.ts +4 -5
  66. package/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.ts +43 -0
  67. package/identity/for_IdentityProvider/when_refreshing/with_type_safe_details.ts +42 -0
  68. package/package.json +1 -1
  69. package/queries/IObservableQueryConnection.ts +10 -0
  70. package/queries/NullObservableQueryConnection.ts +10 -0
  71. package/queries/ObservableQueryConnection.ts +93 -2
  72. package/queries/WebSocketMessage.ts +44 -0
  73. package/queries/for_ObservableQueryConnection/given/an_observable_query_connection.ts +27 -0
  74. package/queries/for_ObservableQueryConnection/when_constructing.ts +15 -0
  75. package/queries/for_ObservableQueryFor/when_performing/with_enumerable_query.ts +5 -2
  76. package/queries/for_ObservableQueryFor/when_performing/with_paging.ts +5 -2
  77. package/queries/for_ObservableQueryFor/when_performing/with_parameter_descriptor_values.ts +5 -2
  78. package/queries/for_ObservableQueryFor/when_performing/with_partial_parameter_descriptor_values.ts +5 -2
  79. package/queries/for_ObservableQueryFor/when_performing/with_route_parameters_and_unused_parameters.ts +5 -2
  80. package/queries/for_ObservableQueryFor/when_performing/with_sorting.ts +5 -2
  81. package/queries/for_ObservableQueryFor/when_performing/with_valid_arguments.ts +7 -2
  82. package/queries/for_QueryFor/when_performing/with_abort_controller.ts +5 -2
  83. package/queries/for_QueryFor/when_performing/with_enumerable_query.ts +5 -2
  84. package/queries/for_QueryFor/when_performing/with_fetch_error.ts +5 -2
  85. package/queries/for_QueryFor/when_performing/with_json_parse_error.ts +6 -3
  86. package/queries/for_QueryFor/when_performing/with_paging.ts +5 -2
  87. package/queries/for_QueryFor/when_performing/with_parameter_descriptor_values.ts +5 -2
  88. package/queries/for_QueryFor/when_performing/with_partial_parameter_descriptor_values.ts +5 -2
  89. package/queries/for_QueryFor/when_performing/with_query_without_required_parameters.ts +5 -2
  90. package/queries/for_QueryFor/when_performing/with_route_parameters_and_unused_parameters.ts +5 -2
  91. package/queries/for_QueryFor/when_performing/with_sorting.ts +7 -3
  92. package/queries/for_QueryFor/when_performing/with_valid_arguments.ts +6 -3
  93. package/queries/for_WebSocketMessage/when_creating_messages.ts +67 -0
  94. package/queries/index.ts +2 -1
@@ -5,15 +5,18 @@ import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
 
7
7
  import * as sinon from 'sinon';
8
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
8
9
  import { QueryResult } from '../../QueryResult';
9
10
 
10
11
  describe('with fetch error', given(a_query_for, context => {
11
12
  let result: QueryResult<string>;
12
13
  let fetchStub: sinon.SinonStub;
14
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
13
15
 
14
16
  beforeEach(async () => {
15
17
  // Setup fetch mock to reject
16
- fetchStub = sinon.stub(global, 'fetch');
18
+ fetchHelper = createFetchHelper();
19
+ fetchStub = fetchHelper.stubFetch();
17
20
  fetchStub.rejects(new Error('Network error'));
18
21
 
19
22
  context.query.setOrigin('https://api.example.com');
@@ -29,7 +32,7 @@ describe('with fetch error', given(a_query_for, context => {
29
32
  });
30
33
 
31
34
  afterEach(() => {
32
- fetchStub.restore();
35
+ fetchHelper.restore();
33
36
  });
34
37
 
35
38
  it('should return no success result', () => {
@@ -5,15 +5,18 @@ import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
 
7
7
  import * as sinon from 'sinon';
8
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
8
9
  import { QueryResult } from '../../QueryResult';
9
10
 
10
11
  describe('with json parse error', given(a_query_for, context => {
11
12
  let result: QueryResult<string>;
12
13
  let fetchStub: sinon.SinonStub;
14
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
13
15
 
14
16
  beforeEach(async () => {
15
- // Setup fetch mock with json parse error
16
- fetchStub = sinon.stub(global, 'fetch');
17
+ // Setup fetch mock with json parse error using helper
18
+ fetchHelper = createFetchHelper();
19
+ fetchStub = fetchHelper.stubFetch();
17
20
  fetchStub.resolves({
18
21
  json: sinon.stub().rejects(new Error('Invalid JSON')),
19
22
  ok: true,
@@ -27,7 +30,7 @@ describe('with json parse error', given(a_query_for, context => {
27
30
  });
28
31
 
29
32
  afterEach(() => {
30
- fetchStub.restore();
33
+ fetchHelper.restore();
31
34
  });
32
35
 
33
36
  it('should return no success result', () => {
@@ -5,12 +5,14 @@ import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
 
7
7
  import * as sinon from 'sinon';
8
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
8
9
  import { QueryResult } from '../../QueryResult';
9
10
  import { Paging } from '../../Paging';
10
11
 
11
12
  describe('with paging', given(a_query_for, context => {
12
13
  let result: QueryResult<string>;
13
14
  let fetchStub: sinon.SinonStub;
15
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
14
16
  const mockResponse = {
15
17
  data: 'test-result',
16
18
  isSuccess: true,
@@ -30,7 +32,8 @@ describe('with paging', given(a_query_for, context => {
30
32
 
31
33
  beforeEach(async () => {
32
34
  // Setup fetch mock
33
- fetchStub = sinon.stub(global, 'fetch');
35
+ fetchHelper = createFetchHelper();
36
+ fetchStub = fetchHelper.stubFetch();
34
37
  fetchStub.resolves({
35
38
  json: sinon.stub().resolves(mockResponse),
36
39
  ok: true,
@@ -45,7 +48,7 @@ describe('with paging', given(a_query_for, context => {
45
48
  });
46
49
 
47
50
  afterEach(() => {
48
- fetchStub.restore();
51
+ fetchHelper.restore();
49
52
  });
50
53
 
51
54
  it('should call fetch with URL including paging parameters', () => {
@@ -4,11 +4,13 @@
4
4
  import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
  import * as sinon from 'sinon';
7
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
7
8
  import { QueryResult } from '../../QueryResult';
8
9
 
9
10
  describe('with parameter descriptor values', given(a_query_for, context => {
10
11
  let result: QueryResult<string>;
11
12
  let fetchStub: sinon.SinonStub;
13
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
12
14
  const mockResponse = {
13
15
  data: 'test-result',
14
16
  isSuccess: true,
@@ -27,7 +29,8 @@ describe('with parameter descriptor values', given(a_query_for, context => {
27
29
  };
28
30
 
29
31
  beforeEach(async () => {
30
- fetchStub = sinon.stub(global, 'fetch');
32
+ fetchHelper = createFetchHelper();
33
+ fetchStub = fetchHelper.stubFetch();
31
34
  fetchStub.resolves({
32
35
  json: sinon.stub().resolves(mockResponse),
33
36
  ok: true,
@@ -45,7 +48,7 @@ describe('with parameter descriptor values', given(a_query_for, context => {
45
48
  });
46
49
 
47
50
  afterEach(() => {
48
- fetchStub.restore();
51
+ fetchHelper.restore();
49
52
  });
50
53
 
51
54
  it('should return successful result', () => {
@@ -4,11 +4,13 @@
4
4
  import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
  import * as sinon from 'sinon';
7
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
7
8
  import { QueryResult } from '../../QueryResult';
8
9
 
9
10
  describe('with partial parameter descriptor values', given(a_query_for, context => {
10
11
  let result: QueryResult<string>;
11
12
  let fetchStub: sinon.SinonStub;
13
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
12
14
  const mockResponse = {
13
15
  data: 'test-result',
14
16
  isSuccess: true,
@@ -27,7 +29,8 @@ describe('with partial parameter descriptor values', given(a_query_for, context
27
29
  };
28
30
 
29
31
  beforeEach(async () => {
30
- fetchStub = sinon.stub(global, 'fetch');
32
+ fetchHelper = createFetchHelper();
33
+ fetchStub = fetchHelper.stubFetch();
31
34
  fetchStub.resolves({
32
35
  json: sinon.stub().resolves(mockResponse),
33
36
  ok: true,
@@ -45,7 +48,7 @@ describe('with partial parameter descriptor values', given(a_query_for, context
45
48
  });
46
49
 
47
50
  afterEach(() => {
48
- fetchStub.restore();
51
+ fetchHelper.restore();
49
52
  });
50
53
 
51
54
  it('should return successful result', () => {
@@ -5,11 +5,13 @@ import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
 
7
7
  import * as sinon from 'sinon';
8
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
8
9
  import { QueryResult } from '../../QueryResult';
9
10
 
10
11
  describe('with query without required parameters', given(a_query_for, context => {
11
12
  let result: QueryResult<string>;
12
13
  let fetchStub: sinon.SinonStub;
14
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
13
15
  const mockResponse = {
14
16
  data: 'test-result',
15
17
  isSuccess: true,
@@ -32,7 +34,8 @@ describe('with query without required parameters', given(a_query_for, context =>
32
34
  if ((global.fetch as sinon.SinonStub)?.restore) {
33
35
  (global.fetch as sinon.SinonStub).restore();
34
36
  }
35
- fetchStub = sinon.stub(global, 'fetch');
37
+ fetchHelper = createFetchHelper();
38
+ fetchStub = fetchHelper.stubFetch();
36
39
  fetchStub.resolves({
37
40
  json: sinon.stub().resolves(mockResponse),
38
41
  ok: true,
@@ -46,7 +49,7 @@ describe('with query without required parameters', given(a_query_for, context =>
46
49
  });
47
50
 
48
51
  afterEach(() => {
49
- fetchStub?.restore();
52
+ fetchHelper.restore();
50
53
  });
51
54
 
52
55
  it('should return successful result', () => {
@@ -4,12 +4,14 @@
4
4
  import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
  import * as sinon from 'sinon';
7
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
7
8
  import { QueryResult } from '../../QueryResult';
8
9
  import { expect } from 'chai';
9
10
 
10
11
  describe('with route parameters and unused parameters', given(a_query_for, context => {
11
12
  let result: QueryResult<string>;
12
13
  let fetchStub: sinon.SinonStub;
14
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
13
15
  const mockResponse = {
14
16
  data: 'test-result',
15
17
  isSuccess: true,
@@ -28,7 +30,8 @@ describe('with route parameters and unused parameters', given(a_query_for, conte
28
30
  };
29
31
 
30
32
  beforeEach(async () => {
31
- fetchStub = sinon.stub(global, 'fetch');
33
+ fetchHelper = createFetchHelper();
34
+ fetchStub = fetchHelper.stubFetch();
32
35
  fetchStub.resolves({
33
36
  json: sinon.stub().resolves(mockResponse),
34
37
  ok: true,
@@ -43,7 +46,7 @@ describe('with route parameters and unused parameters', given(a_query_for, conte
43
46
  });
44
47
 
45
48
  afterEach(() => {
46
- fetchStub.restore();
49
+ fetchHelper.restore();
47
50
  });
48
51
 
49
52
  it('should return successful result', () => {
@@ -5,6 +5,7 @@ import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
 
7
7
  import * as sinon from 'sinon';
8
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
8
9
  import { QueryResult } from '../../QueryResult';
9
10
  import { Sorting } from '../../Sorting';
10
11
  import { SortDirection } from '../../SortDirection';
@@ -12,6 +13,7 @@ import { SortDirection } from '../../SortDirection';
12
13
  describe('with sorting', given(a_query_for, context => {
13
14
  let result: QueryResult<string>;
14
15
  let fetchStub: sinon.SinonStub;
16
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
15
17
  const mockResponse = {
16
18
  data: 'test-result',
17
19
  isSuccess: true,
@@ -32,7 +34,8 @@ describe('with sorting', given(a_query_for, context => {
32
34
  describe('and ascending direction', () => {
33
35
  beforeEach(async () => {
34
36
  // Setup fetch mock
35
- fetchStub = sinon.stub(global, 'fetch');
37
+ fetchHelper = createFetchHelper();
38
+ fetchStub = fetchHelper.stubFetch();
36
39
  fetchStub.resolves({
37
40
  json: sinon.stub().resolves(mockResponse),
38
41
  ok: true,
@@ -66,7 +69,8 @@ describe('with sorting', given(a_query_for, context => {
66
69
  describe('and descending direction', () => {
67
70
  beforeEach(async () => {
68
71
  // Setup fetch mock
69
- fetchStub = sinon.stub(global, 'fetch');
72
+ fetchHelper = createFetchHelper();
73
+ fetchStub = fetchHelper.stubFetch();
70
74
  fetchStub.resolves({
71
75
  json: sinon.stub().resolves(mockResponse),
72
76
  ok: true,
@@ -81,7 +85,7 @@ describe('with sorting', given(a_query_for, context => {
81
85
  });
82
86
 
83
87
  afterEach(() => {
84
- fetchStub.restore();
88
+ fetchHelper.restore();
85
89
  });
86
90
 
87
91
  it('should call fetch with URL including sorting parameters', () => {
@@ -4,11 +4,13 @@
4
4
  import { a_query_for } from '../given/a_query_for';
5
5
  import { given } from '../../../given';
6
6
  import * as sinon from 'sinon';
7
+ import { createFetchHelper } from '../../../helpers/fetchHelper';
7
8
  import { QueryResult } from '../../QueryResult';
8
9
 
9
10
  describe('with valid arguments', given(a_query_for, context => {
10
11
  let result: QueryResult<string>;
11
12
  let fetchStub: sinon.SinonStub;
13
+ let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
12
14
  const mockResponse = {
13
15
  data: 'test-result',
14
16
  isSuccess: true,
@@ -27,8 +29,9 @@ describe('with valid arguments', given(a_query_for, context => {
27
29
  };
28
30
 
29
31
  beforeEach(async () => {
30
- // Setup fetch mock
31
- fetchStub = sinon.stub(global, 'fetch');
32
+ // Setup fetch mock using helper
33
+ fetchHelper = createFetchHelper();
34
+ fetchStub = fetchHelper.stubFetch();
32
35
  fetchStub.resolves({
33
36
  json: sinon.stub().resolves(mockResponse),
34
37
  ok: true,
@@ -44,7 +47,7 @@ describe('with valid arguments', given(a_query_for, context => {
44
47
  });
45
48
 
46
49
  afterEach(() => {
47
- fetchStub.restore();
50
+ fetchHelper.restore();
48
51
  });
49
52
 
50
53
  it('should return successful result', () => {
@@ -0,0 +1,67 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { WebSocketMessage, WebSocketMessageType } from '../WebSocketMessage';
5
+
6
+ describe('when creating a ping message', () => {
7
+ let timestamp: number;
8
+ let message: WebSocketMessage;
9
+
10
+ beforeEach(() => {
11
+ timestamp = Date.now();
12
+ message = {
13
+ type: WebSocketMessageType.Ping,
14
+ timestamp: timestamp
15
+ };
16
+ });
17
+
18
+ it('should have ping type', () => {
19
+ message.type.should.equal(WebSocketMessageType.Ping);
20
+ });
21
+
22
+ it('should have timestamp', () => {
23
+ message.timestamp!.should.equal(timestamp);
24
+ });
25
+ });
26
+
27
+ describe('when creating a pong message', () => {
28
+ let timestamp: number;
29
+ let message: WebSocketMessage;
30
+
31
+ beforeEach(() => {
32
+ timestamp = Date.now();
33
+ message = {
34
+ type: WebSocketMessageType.Pong,
35
+ timestamp: timestamp
36
+ };
37
+ });
38
+
39
+ it('should have pong type', () => {
40
+ message.type.should.equal(WebSocketMessageType.Pong);
41
+ });
42
+
43
+ it('should have timestamp', () => {
44
+ message.timestamp!.should.equal(timestamp);
45
+ });
46
+ });
47
+
48
+ describe('when creating a data message', () => {
49
+ let data: object;
50
+ let message: WebSocketMessage;
51
+
52
+ beforeEach(() => {
53
+ data = { test: 'value' };
54
+ message = {
55
+ type: WebSocketMessageType.Data,
56
+ data: data
57
+ };
58
+ });
59
+
60
+ it('should have data type', () => {
61
+ message.type.should.equal(WebSocketMessageType.Data);
62
+ });
63
+
64
+ it('should have data', () => {
65
+ message.data.should.equal(data);
66
+ });
67
+ });
package/queries/index.ts CHANGED
@@ -17,5 +17,6 @@ export * from './ObservableQueryFor';
17
17
  export * from './IObservableQueryConnection';
18
18
  export * from './ObservableQueryConnection';
19
19
  export * from './ObservableQuerySubscription';
20
+ export * from './WebSocketMessage';
20
21
  export * from './IQueryProvider';
21
- export * from './QueryProvider';
22
+ export * from './QueryProvider';