@cratis/arc 20.0.0 → 20.1.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.
Files changed (66) hide show
  1. package/ICanBeConfigured.ts +1 -1
  2. package/UrlHelpers.ts +14 -1
  3. package/dist/cjs/ICanBeConfigured.d.ts +1 -1
  4. package/dist/cjs/ICanBeConfigured.d.ts.map +1 -1
  5. package/dist/cjs/UrlHelpers.d.ts.map +1 -1
  6. package/dist/cjs/UrlHelpers.js +11 -1
  7. package/dist/cjs/UrlHelpers.js.map +1 -1
  8. package/dist/cjs/identity/IdentityProvider.d.ts +1 -1
  9. package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
  10. package/dist/cjs/identity/IdentityProvider.js.map +1 -1
  11. package/dist/cjs/queries/for_QueryFor/given/TestQueries.d.ts +9 -0
  12. package/dist/cjs/queries/for_QueryFor/given/TestQueries.d.ts.map +1 -1
  13. package/dist/cjs/queries/for_QueryFor/given/a_query_for.d.ts +2 -1
  14. package/dist/cjs/queries/for_QueryFor/given/a_query_for.d.ts.map +1 -1
  15. package/dist/cjs/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts +2 -0
  16. package/dist/cjs/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts.map +1 -0
  17. package/dist/cjs/reflection/ParameterDescriptor.d.ts +2 -1
  18. package/dist/cjs/reflection/ParameterDescriptor.d.ts.map +1 -1
  19. package/dist/cjs/reflection/ParameterDescriptor.js +3 -1
  20. package/dist/cjs/reflection/ParameterDescriptor.js.map +1 -1
  21. package/dist/esm/ICanBeConfigured.d.ts +1 -1
  22. package/dist/esm/ICanBeConfigured.d.ts.map +1 -1
  23. package/dist/esm/UrlHelpers.d.ts.map +1 -1
  24. package/dist/esm/UrlHelpers.js +11 -1
  25. package/dist/esm/UrlHelpers.js.map +1 -1
  26. package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.d.ts +2 -0
  27. package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.d.ts.map +1 -0
  28. package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.js +16 -0
  29. package/dist/esm/for_UrlHelpers/when_building_query_params/with_array_values.js.map +1 -0
  30. package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.d.ts +2 -0
  31. package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.d.ts.map +1 -0
  32. package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.js +17 -0
  33. package/dist/esm/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.js.map +1 -0
  34. package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.d.ts +2 -0
  35. package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.d.ts.map +1 -0
  36. package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.js +17 -0
  37. package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.js.map +1 -0
  38. package/dist/esm/identity/IdentityProvider.d.ts +1 -1
  39. package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
  40. package/dist/esm/identity/IdentityProvider.js.map +1 -1
  41. package/dist/esm/queries/for_QueryFor/given/TestQueries.d.ts +9 -0
  42. package/dist/esm/queries/for_QueryFor/given/TestQueries.d.ts.map +1 -1
  43. package/dist/esm/queries/for_QueryFor/given/TestQueries.js +16 -0
  44. package/dist/esm/queries/for_QueryFor/given/TestQueries.js.map +1 -1
  45. package/dist/esm/queries/for_QueryFor/given/a_query_for.d.ts +2 -1
  46. package/dist/esm/queries/for_QueryFor/given/a_query_for.d.ts.map +1 -1
  47. package/dist/esm/queries/for_QueryFor/given/a_query_for.js +3 -1
  48. package/dist/esm/queries/for_QueryFor/given/a_query_for.js.map +1 -1
  49. package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts +2 -0
  50. package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.d.ts.map +1 -0
  51. package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.js +66 -0
  52. package/dist/esm/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.js.map +1 -0
  53. package/dist/esm/reflection/ParameterDescriptor.d.ts +2 -1
  54. package/dist/esm/reflection/ParameterDescriptor.d.ts.map +1 -1
  55. package/dist/esm/reflection/ParameterDescriptor.js +3 -1
  56. package/dist/esm/reflection/ParameterDescriptor.js.map +1 -1
  57. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  58. package/for_UrlHelpers/when_building_query_params/with_array_values.ts +22 -0
  59. package/for_UrlHelpers/when_building_query_params/with_mixed_array_and_scalar_values.ts +23 -0
  60. package/for_UrlHelpers/when_replacing_route_parameters/with_array_parameters.ts +23 -0
  61. package/identity/IdentityProvider.ts +1 -1
  62. package/package.json +2 -2
  63. package/queries/for_QueryFor/given/TestQueries.ts +20 -0
  64. package/queries/for_QueryFor/given/a_query_for.ts +4 -1
  65. package/queries/for_QueryFor/when_performing/with_enumerable_parameter_descriptor_values.ts +82 -0
  66. 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.0.0",
3
+ "version": "20.1.1",
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
- "dependencies": {
66
+ "peerDependencies": {
67
67
  "@cratis/fundamentals": "^7.7.1"
68
68
  }
69
69
  }
@@ -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
  }