@cratis/arc 20.1.0 → 20.1.3
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/Globals.ts +7 -0
- package/ICanBeConfigured.ts +1 -1
- package/UrlHelpers.ts +14 -1
- package/dist/cjs/Globals.d.ts +2 -0
- package/dist/cjs/Globals.d.ts.map +1 -1
- package/dist/cjs/Globals.js +1 -0
- package/dist/cjs/Globals.js.map +1 -1
- package/dist/cjs/ICanBeConfigured.d.ts +1 -1
- package/dist/cjs/ICanBeConfigured.d.ts.map +1 -1
- package/dist/cjs/UrlHelpers.d.ts.map +1 -1
- package/dist/cjs/UrlHelpers.js +11 -1
- package/dist/cjs/UrlHelpers.js.map +1 -1
- package/dist/cjs/identity/IdentityProvider.d.ts +1 -1
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.js +4 -2
- package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/cjs/queries/for_QueryFor/given/TestQueries.d.ts +9 -0
- package/dist/cjs/queries/for_QueryFor/given/TestQueries.d.ts.map +1 -1
- package/dist/cjs/queries/for_QueryFor/given/a_query_for.d.ts +2 -1
- package/dist/cjs/queries/for_QueryFor/given/a_query_for.d.ts.map +1 -1
- package/dist/cjs/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts +2 -0
- package/dist/cjs/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts.map +1 -0
- package/dist/cjs/reflection/ParameterDescriptor.d.ts +2 -1
- package/dist/cjs/reflection/ParameterDescriptor.d.ts.map +1 -1
- package/dist/cjs/reflection/ParameterDescriptor.js +3 -1
- package/dist/cjs/reflection/ParameterDescriptor.js.map +1 -1
- package/dist/esm/Globals.d.ts +2 -0
- package/dist/esm/Globals.d.ts.map +1 -1
- package/dist/esm/Globals.js +1 -0
- package/dist/esm/Globals.js.map +1 -1
- package/dist/esm/ICanBeConfigured.d.ts +1 -1
- package/dist/esm/ICanBeConfigured.d.ts.map +1 -1
- package/dist/esm/UrlHelpers.d.ts.map +1 -1
- package/dist/esm/UrlHelpers.js +11 -1
- package/dist/esm/UrlHelpers.js.map +1 -1
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.d.ts +2 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.d.ts.map +1 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.js +16 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.js.map +1 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.d.ts +2 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.d.ts.map +1 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.js +17 -0
- package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.js.map +1 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.d.ts +2 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.d.ts.map +1 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.js +17 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.js.map +1 -0
- package/dist/esm/identity/IdentityProvider.d.ts +1 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.js +4 -2
- package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/TestQueries.d.ts +9 -0
- package/dist/esm/queries/for_QueryFor/given/TestQueries.d.ts.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/TestQueries.js +16 -0
- package/dist/esm/queries/for_QueryFor/given/TestQueries.js.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.d.ts +2 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.d.ts.map +1 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.js +3 -1
- package/dist/esm/queries/for_QueryFor/given/a_query_for.js.map +1 -1
- package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts +2 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.js +66 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.js.map +1 -0
- package/dist/esm/reflection/ParameterDescriptor.d.ts +2 -1
- package/dist/esm/reflection/ParameterDescriptor.d.ts.map +1 -1
- package/dist/esm/reflection/ParameterDescriptor.js +3 -1
- package/dist/esm/reflection/ParameterDescriptor.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/for_UrlHelpers/when_building_query_params/with_array_values.ts +22 -0
- package/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.ts +23 -0
- package/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.ts +23 -0
- package/identity/IdentityProvider.ts +1 -1
- package/package.json +2 -2
- package/queries/ServerSentEventHubConnection.ts +6 -2
- package/queries/for_QueryFor/given/TestQueries.ts +20 -0
- package/queries/for_QueryFor/given/a_query_for.ts +4 -1
- package/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.ts +82 -0
- package/reflection/ParameterDescriptor.ts +2 -1
|
@@ -0,0 +1,22 @@
|
|
|
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 { describe, it, beforeEach } from 'vitest';
|
|
5
|
+
import { UrlHelpers } from '../../UrlHelpers';
|
|
6
|
+
|
|
7
|
+
describe('when building query params with array values', () => {
|
|
8
|
+
let unusedParameters: object;
|
|
9
|
+
let result: URLSearchParams;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
unusedParameters = { names: ['Alice', 'Bob', 'Charlie'] };
|
|
13
|
+
|
|
14
|
+
result = UrlHelpers.buildQueryParams(unusedParameters);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should append first value', () => result.getAll('names').should.include('Alice'));
|
|
18
|
+
it('should append second value', () => result.getAll('names').should.include('Bob'));
|
|
19
|
+
it('should append third value', () => result.getAll('names').should.include('Charlie'));
|
|
20
|
+
it('should have three entries for the key', () => result.getAll('names').length.should.equal(3));
|
|
21
|
+
it('should have only one unique key', () => Array.from(new Set(result.keys())).length.should.equal(1));
|
|
22
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { describe, it, beforeEach } from 'vitest';
|
|
5
|
+
import { UrlHelpers } from '../../UrlHelpers';
|
|
6
|
+
|
|
7
|
+
describe('when building query params with mixed array and scalar values', () => {
|
|
8
|
+
let unusedParameters: object;
|
|
9
|
+
let result: URLSearchParams;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
unusedParameters = { filter: 'active', ids: [1, 2, 3] };
|
|
13
|
+
|
|
14
|
+
result = UrlHelpers.buildQueryParams(unusedParameters);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should contain scalar filter parameter', () => result.get('filter')!.should.equal('active'));
|
|
18
|
+
it('should append first id value', () => result.getAll('ids').should.include('1'));
|
|
19
|
+
it('should append second id value', () => result.getAll('ids').should.include('2'));
|
|
20
|
+
it('should append third id value', () => result.getAll('ids').should.include('3'));
|
|
21
|
+
it('should have three entries for ids key', () => result.getAll('ids').length.should.equal(3));
|
|
22
|
+
it('should have two unique keys', () => Array.from(new Set(result.keys())).length.should.equal(2));
|
|
23
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { describe, it, beforeEach } from 'vitest';
|
|
5
|
+
import { UrlHelpers } from '../../UrlHelpers';
|
|
6
|
+
|
|
7
|
+
describe('when replacing route parameters with array values', () => {
|
|
8
|
+
let route: string;
|
|
9
|
+
let parameters: object;
|
|
10
|
+
let result: { route: string; unusedParameters: object };
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
route = '/api/search?names={names}&ids={ids}';
|
|
14
|
+
parameters = { names: ['Alice', 'Bob'], ids: [1, 2, 3] };
|
|
15
|
+
|
|
16
|
+
result = UrlHelpers.replaceRouteParameters(route, parameters);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should leave route template placeholders untouched for array values', () => result.route.should.equal('/api/search?names={names}&ids={ids}'));
|
|
20
|
+
it('should keep all array parameters as unused', () => Object.keys(result.unusedParameters).length.should.equal(2));
|
|
21
|
+
it('should contain names array in unused parameters', () => (result.unusedParameters as Record<string, string[]>)['names'].should.deep.equal(['Alice', 'Bob']));
|
|
22
|
+
it('should contain ids array in unused parameters', () => (result.unusedParameters as Record<string, number[]>)['ids'].should.deep.equal([1, 2, 3]));
|
|
23
|
+
});
|
|
@@ -5,7 +5,7 @@ import { Constructor, JsonSerializer } from '@cratis/fundamentals';
|
|
|
5
5
|
import { IIdentityProvider } from './IIdentityProvider';
|
|
6
6
|
import { IIdentity } from './IIdentity';
|
|
7
7
|
import { IdentityProviderResult } from './IdentityProviderResult';
|
|
8
|
-
import { GetHttpHeaders } from 'GetHttpHeaders';
|
|
8
|
+
import { GetHttpHeaders } from '../GetHttpHeaders';
|
|
9
9
|
import { Globals } from '../Globals';
|
|
10
10
|
import { UrlHelpers } from '../UrlHelpers';
|
|
11
11
|
import { joinPaths } from '../joinPaths';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/arc",
|
|
3
|
-
"version": "20.1.
|
|
3
|
+
"version": "20.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Cratis",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"ci": "yarn g:ci",
|
|
64
64
|
"up": "yarn g:up"
|
|
65
65
|
},
|
|
66
|
-
"
|
|
66
|
+
"peerDependencies": {
|
|
67
67
|
"@cratis/fundamentals": "^7.7.1"
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -281,9 +281,11 @@ export class ServerSentEventHubConnection implements IObservableQueryHubConnecti
|
|
|
281
281
|
request,
|
|
282
282
|
};
|
|
283
283
|
|
|
284
|
+
const customHeaders = Globals.httpHeadersCallback?.() ?? {};
|
|
285
|
+
|
|
284
286
|
fetch(this._subscribeUrl, {
|
|
285
287
|
method: 'POST',
|
|
286
|
-
headers: { 'Content-Type': 'application/json' },
|
|
288
|
+
headers: { 'Content-Type': 'application/json', ...customHeaders },
|
|
287
289
|
body: JSON.stringify(body),
|
|
288
290
|
}).catch(error => {
|
|
289
291
|
console.error(`SSE hub: subscribe POST failed for '${queryId}'`, error);
|
|
@@ -298,9 +300,11 @@ export class ServerSentEventHubConnection implements IObservableQueryHubConnecti
|
|
|
298
300
|
queryId,
|
|
299
301
|
};
|
|
300
302
|
|
|
303
|
+
const customHeaders = Globals.httpHeadersCallback?.() ?? {};
|
|
304
|
+
|
|
301
305
|
fetch(this._unsubscribeUrl, {
|
|
302
306
|
method: 'POST',
|
|
303
|
-
headers: { 'Content-Type': 'application/json' },
|
|
307
|
+
headers: { 'Content-Type': 'application/json', ...customHeaders },
|
|
304
308
|
body: JSON.stringify(body),
|
|
305
309
|
}).catch(error => {
|
|
306
310
|
console.error(`SSE hub: unsubscribe POST failed for '${queryId}'`, error);
|
|
@@ -71,6 +71,26 @@ export class TestQueryForWithParameterDescriptorValues extends QueryFor<string,
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
export class TestQueryForWithEnumerableParameterDescriptorValues extends QueryFor<string[], object> {
|
|
75
|
+
readonly route = '/api/search-by-lists';
|
|
76
|
+
readonly defaultValue: string[] = [];
|
|
77
|
+
readonly parameterDescriptors: ParameterDescriptor[] = [
|
|
78
|
+
new ParameterDescriptor('names', String as Constructor, true),
|
|
79
|
+
new ParameterDescriptor('ids', Number as Constructor, true)
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
names?: string[];
|
|
83
|
+
ids?: number[];
|
|
84
|
+
|
|
85
|
+
get requiredRequestParameters(): string[] {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
constructor() {
|
|
90
|
+
super(String as Constructor, true);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
74
94
|
export interface TestQueryForWithMultipleRequiredParametersArguments {
|
|
75
95
|
userId: string;
|
|
76
96
|
category: string;
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
TestEnumerableQueryFor,
|
|
7
7
|
TestQueryForWithoutRequiredParams,
|
|
8
8
|
TestQueryForWithParameterDescriptorValues,
|
|
9
|
-
TestQueryForWithMultipleRequiredParameters
|
|
9
|
+
TestQueryForWithMultipleRequiredParameters,
|
|
10
|
+
TestQueryForWithEnumerableParameterDescriptorValues
|
|
10
11
|
} from './TestQueries';
|
|
11
12
|
|
|
12
13
|
export class a_query_for {
|
|
@@ -14,6 +15,7 @@ export class a_query_for {
|
|
|
14
15
|
enumerableQuery: TestEnumerableQueryFor;
|
|
15
16
|
queryWithoutParams: TestQueryForWithoutRequiredParams;
|
|
16
17
|
queryWithParameterDescriptorValues: TestQueryForWithParameterDescriptorValues;
|
|
18
|
+
queryWithEnumerableParameterDescriptorValues: TestQueryForWithEnumerableParameterDescriptorValues;
|
|
17
19
|
queryWithMultipleRequiredParameters: TestQueryForWithMultipleRequiredParameters;
|
|
18
20
|
|
|
19
21
|
constructor() {
|
|
@@ -21,6 +23,7 @@ export class a_query_for {
|
|
|
21
23
|
this.enumerableQuery = new TestEnumerableQueryFor();
|
|
22
24
|
this.queryWithoutParams = new TestQueryForWithoutRequiredParams();
|
|
23
25
|
this.queryWithParameterDescriptorValues = new TestQueryForWithParameterDescriptorValues();
|
|
26
|
+
this.queryWithEnumerableParameterDescriptorValues = new TestQueryForWithEnumerableParameterDescriptorValues();
|
|
24
27
|
this.queryWithMultipleRequiredParameters = new TestQueryForWithMultipleRequiredParameters();
|
|
25
28
|
}
|
|
26
29
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { a_query_for } from '../given/a_query_for';
|
|
5
|
+
import { given } from '../../../given';
|
|
6
|
+
import * as sinon from 'sinon';
|
|
7
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
8
|
+
import { QueryResult } from '../../QueryResult';
|
|
9
|
+
|
|
10
|
+
describe('with enumerable parameter descriptor values', given(a_query_for, context => {
|
|
11
|
+
let result: QueryResult<string[]>;
|
|
12
|
+
let fetchStub: sinon.SinonStub;
|
|
13
|
+
let fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
|
|
14
|
+
const mockResponse = {
|
|
15
|
+
data: [],
|
|
16
|
+
isSuccess: true,
|
|
17
|
+
isAuthorized: true,
|
|
18
|
+
isValid: true,
|
|
19
|
+
hasExceptions: false,
|
|
20
|
+
validationResults: [],
|
|
21
|
+
exceptionMessages: [],
|
|
22
|
+
exceptionStackTrace: '',
|
|
23
|
+
paging: {
|
|
24
|
+
totalItems: 0,
|
|
25
|
+
totalPages: 0,
|
|
26
|
+
page: 0,
|
|
27
|
+
size: 0
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
beforeEach(async () => {
|
|
32
|
+
fetchHelper = createFetchHelper();
|
|
33
|
+
fetchStub = fetchHelper.stubFetch();
|
|
34
|
+
fetchStub.resolves({
|
|
35
|
+
json: sinon.stub().resolves(mockResponse),
|
|
36
|
+
ok: true,
|
|
37
|
+
status: 200
|
|
38
|
+
} as unknown as Response);
|
|
39
|
+
|
|
40
|
+
context.queryWithEnumerableParameterDescriptorValues.setOrigin('https://api.example.com');
|
|
41
|
+
context.queryWithEnumerableParameterDescriptorValues.setApiBasePath('/api/v1');
|
|
42
|
+
|
|
43
|
+
// Set enumerable values on the query instance
|
|
44
|
+
context.queryWithEnumerableParameterDescriptorValues.names = ['Alice', 'Bob'];
|
|
45
|
+
context.queryWithEnumerableParameterDescriptorValues.ids = [1, 2, 3];
|
|
46
|
+
|
|
47
|
+
result = await context.queryWithEnumerableParameterDescriptorValues.perform();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
fetchHelper.restore();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return successful result', () => {
|
|
55
|
+
result.isSuccess.should.be.true;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should include first name in URL as repeated query parameter', () => {
|
|
59
|
+
const url = fetchStub.getCall(0).args[0].href;
|
|
60
|
+
url.should.include('names=Alice');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should include second name in URL as repeated query parameter', () => {
|
|
64
|
+
const url = fetchStub.getCall(0).args[0].href;
|
|
65
|
+
url.should.include('names=Bob');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should include first id in URL as repeated query parameter', () => {
|
|
69
|
+
const url = fetchStub.getCall(0).args[0].href;
|
|
70
|
+
url.should.include('ids=1');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should include second id in URL as repeated query parameter', () => {
|
|
74
|
+
const url = fetchStub.getCall(0).args[0].href;
|
|
75
|
+
url.should.include('ids=2');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should include third id in URL as repeated query parameter', () => {
|
|
79
|
+
const url = fetchStub.getCall(0).args[0].href;
|
|
80
|
+
url.should.include('ids=3');
|
|
81
|
+
});
|
|
82
|
+
}));
|
|
@@ -11,7 +11,8 @@ export class ParameterDescriptor {
|
|
|
11
11
|
* Initializes a new instance of the {@link ParameterDescriptor} class.
|
|
12
12
|
* @param name Name of the parameter.
|
|
13
13
|
* @param type Type of the parameter.
|
|
14
|
+
* @param isEnumerable Whether the parameter is an enumerable (collection) type.
|
|
14
15
|
*/
|
|
15
|
-
constructor(readonly name: string, readonly type: Constructor) {
|
|
16
|
+
constructor(readonly name: string, readonly type: Constructor, readonly isEnumerable: boolean = false) {
|
|
16
17
|
}
|
|
17
18
|
}
|