@cratis/arc 22.50.5 → 22.50.6
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/UrlHelpers.ts +2 -1
- package/dist/cjs/UrlHelpers.d.ts.map +1 -1
- package/dist/cjs/UrlHelpers.js +2 -1
- package/dist/cjs/UrlHelpers.js.map +1 -1
- package/dist/esm/UrlHelpers.d.ts.map +1 -1
- package/dist/esm/UrlHelpers.js +2 -1
- package/dist/esm/UrlHelpers.js.map +1 -1
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_regular_expression_metacharacters.d.ts +2 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_regular_expression_metacharacters.d.ts.map +1 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_regular_expression_metacharacters.js +25 -0
- package/dist/esm/for_UrlHelpers/when_replacing_route_parameters/with_regular_expression_metacharacters.js.map +1 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_regular_expression_metacharacters_in_parameter_keys.d.ts +2 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_regular_expression_metacharacters_in_parameter_keys.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_regular_expression_metacharacters_in_parameter_keys.js +59 -0
- package/dist/esm/queries/for_QueryFor/when_performing/with_regular_expression_metacharacters_in_parameter_keys.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/for_UrlHelpers/when_replacing_route_parameters/with_regular_expression_metacharacters.ts +31 -0
- package/package.json +3 -3
- package/queries/for_QueryFor/when_performing/with_regular_expression_metacharacters_in_parameter_keys.ts +67 -0
package/for_UrlHelpers/when_replacing_route_parameters/with_regular_expression_metacharacters.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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, expect } from 'vitest';
|
|
5
|
+
import { UrlHelpers } from '../../UrlHelpers.js';
|
|
6
|
+
|
|
7
|
+
describe('when replacing route parameters with regular expression metacharacters', () => {
|
|
8
|
+
for (const key of ['a[', 'a.b', 'a+b', 'a*b', 'a?b', 'a^b', 'a$b', 'a{b}', 'a(b)', 'a|b', 'a\\b', 'a]b']) {
|
|
9
|
+
it(`should replace the literal placeholder for ${key}`, () => {
|
|
10
|
+
const result = UrlHelpers.replaceRouteParameters(`/items/{${key}}/{${key}}`, { [key]: 'value /' });
|
|
11
|
+
expect(result.route).to.equal('/items/value%20%2F/value%20%2F');
|
|
12
|
+
expect(result.unusedParameters).to.deep.equal({});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it(`should leave ${key} unused on a literal route`, () => {
|
|
16
|
+
const result = UrlHelpers.replaceRouteParameters('/items/snapshot', { [key]: 'value' });
|
|
17
|
+
expect(result.route).to.equal('/items/snapshot');
|
|
18
|
+
expect(result.unusedParameters).to.deep.equal({ [key]: 'value' });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
it('should not match a different placeholder through a wildcard', () => {
|
|
23
|
+
const result = UrlHelpers.replaceRouteParameters('/items/{axb}/{a.b}', { 'a.b': 'value' });
|
|
24
|
+
expect(result.route).to.equal('/items/{axb}/value');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should retain case insensitive matching', () => {
|
|
28
|
+
const result = UrlHelpers.replaceRouteParameters('/items/{A.B}', { 'a.b': 'value' });
|
|
29
|
+
expect(result.route).to.equal('/items/value');
|
|
30
|
+
});
|
|
31
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@cratis/arc",
|
|
4
|
-
"version": "22.50.
|
|
4
|
+
"version": "22.50.6",
|
|
5
5
|
"description": "TypeScript command, query, validation, identity, and messaging runtime for Cratis Arc — the CQRS application framework for ASP.NET Core — used by generated proxies.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cratis",
|
|
@@ -118,10 +118,10 @@
|
|
|
118
118
|
"up": "yarn g:up"
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
|
-
"@cratis/fundamentals": "^7.
|
|
121
|
+
"@cratis/fundamentals": "^7.22.4",
|
|
122
122
|
"rxjs": "^7.8.2"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
|
-
"@cratis/fundamentals": "7.
|
|
125
|
+
"@cratis/fundamentals": "7.22.4"
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -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 { describe, it, beforeEach, afterEach, expect } from 'vitest';
|
|
5
|
+
import * as sinon from 'sinon';
|
|
6
|
+
import { QueryFor } from '../../QueryFor.js';
|
|
7
|
+
import { QueryHttpMethod } from '../../QueryHttpMethod.js';
|
|
8
|
+
import { ParameterDescriptor } from '../../../reflection/ParameterDescriptor.js';
|
|
9
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper.js';
|
|
10
|
+
|
|
11
|
+
class QueryWithLiteralParameterKeys extends QueryFor<string, Record<string, string>> {
|
|
12
|
+
readonly defaultValue = '';
|
|
13
|
+
readonly parameterDescriptors: ParameterDescriptor[] = [];
|
|
14
|
+
readonly requiredRequestParameters: string[] = [];
|
|
15
|
+
|
|
16
|
+
constructor(readonly route: string) {
|
|
17
|
+
super(String, false);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (const method of [QueryHttpMethod.Get, QueryHttpMethod.Query]) {
|
|
22
|
+
describe(`when performing ${method} with metacharacters in parameter keys`, () => {
|
|
23
|
+
let fetchHelper: ReturnType<typeof createFetchHelper>;
|
|
24
|
+
let fetchStub: sinon.SinonStub;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
fetchHelper = createFetchHelper();
|
|
28
|
+
fetchStub = fetchHelper.stubFetch();
|
|
29
|
+
fetchStub.resolves({
|
|
30
|
+
ok: true,
|
|
31
|
+
status: 200,
|
|
32
|
+
json: sinon.stub().resolves({
|
|
33
|
+
data: 'result', isSuccess: true, isAuthorized: true, isValid: true,
|
|
34
|
+
hasExceptions: false, validationResults: [], exceptionMessages: [],
|
|
35
|
+
exceptionStackTrace: '', paging: { totalItems: 0, totalPages: 0, page: 0, size: 0 }
|
|
36
|
+
})
|
|
37
|
+
} as unknown as Response);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => fetchHelper.restore());
|
|
41
|
+
|
|
42
|
+
for (const route of ['/items/snapshot', '/items/{a[}/{a.b}']) {
|
|
43
|
+
it(`should fetch ${route} with literal keys`, async () => {
|
|
44
|
+
const query = new QueryWithLiteralParameterKeys(route);
|
|
45
|
+
query.setOrigin('https://api.example.com');
|
|
46
|
+
query.setHttpMethod(method);
|
|
47
|
+
const parameters = { 'a[': 'first', 'a.b': 'second' };
|
|
48
|
+
|
|
49
|
+
const result = await query.perform(parameters);
|
|
50
|
+
|
|
51
|
+
expect(result.isSuccess).to.be.true;
|
|
52
|
+
expect(fetchStub.calledOnce).to.be.true;
|
|
53
|
+
const [url, options] = fetchStub.firstCall.args as [URL, RequestInit];
|
|
54
|
+
expect(options.method).to.equal(method.toUpperCase());
|
|
55
|
+
expect(url.pathname).to.equal(route.includes('{') ? '/items/first/second' : '/items/snapshot');
|
|
56
|
+
if (!route.includes('{')) {
|
|
57
|
+
if (method === QueryHttpMethod.Get) {
|
|
58
|
+
expect(url.searchParams.get('a[')).to.equal('first');
|
|
59
|
+
expect(url.searchParams.get('a.b')).to.equal('second');
|
|
60
|
+
} else {
|
|
61
|
+
expect(JSON.parse(options.body as string).arguments).to.deep.equal(parameters);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|