@cratis/arc 18.4.2 → 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.
- package/commands/for_Command/given/a_command.ts +4 -5
- package/commands/for_Command/when_executing/with_custom_http_headers.ts +4 -1
- package/commands/for_Command/when_executing/with_origin_and_api_base_path.ts +5 -2
- package/commands/for_Command/when_executing/with_route_parameters.ts +4 -2
- package/dist/cjs/helpers/fetchHelper.d.ts +7 -0
- package/dist/cjs/helpers/fetchHelper.d.ts.map +1 -0
- package/dist/cjs/identity/IIdentityProvider.d.ts +2 -1
- package/dist/cjs/identity/IIdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IIdentityProvider.js.map +1 -1
- package/dist/cjs/identity/IdentityProvider.d.ts +4 -3
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +12 -9
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/queries/IObservableQueryConnection.d.ts +2 -0
- package/dist/cjs/queries/IObservableQueryConnection.d.ts.map +1 -1
- package/dist/cjs/queries/NullObservableQueryConnection.d.ts +2 -0
- package/dist/cjs/queries/NullObservableQueryConnection.d.ts.map +1 -1
- package/dist/cjs/queries/NullObservableQueryConnection.js +6 -0
- package/dist/cjs/queries/NullObservableQueryConnection.js.map +1 -1
- package/dist/cjs/queries/ObservableQueryConnection.d.ts +14 -1
- package/dist/cjs/queries/ObservableQueryConnection.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryConnection.js +73 -2
- package/dist/cjs/queries/ObservableQueryConnection.js.map +1 -1
- package/dist/cjs/queries/WebSocketMessage.d.ts +11 -0
- package/dist/cjs/queries/WebSocketMessage.d.ts.map +1 -0
- package/dist/cjs/queries/WebSocketMessage.js +9 -0
- package/dist/cjs/queries/WebSocketMessage.js.map +1 -0
- package/dist/cjs/queries/index.d.ts +1 -0
- package/dist/cjs/queries/index.d.ts.map +1 -1
- package/dist/cjs/queries/index.js +5 -0
- package/dist/cjs/queries/index.js.map +1 -1
- package/dist/esm/helpers/fetchHelper.d.ts +7 -0
- package/dist/esm/helpers/fetchHelper.d.ts.map +1 -0
- package/dist/esm/helpers/fetchHelper.js +22 -0
- package/dist/esm/helpers/fetchHelper.js.map +1 -0
- package/dist/esm/identity/IIdentityProvider.d.ts +2 -1
- package/dist/esm/identity/IIdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IIdentityProvider.js.map +1 -1
- package/dist/esm/identity/IdentityProvider.d.ts +4 -3
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +12 -9
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/queries/IObservableQueryConnection.d.ts +2 -0
- package/dist/esm/queries/IObservableQueryConnection.d.ts.map +1 -1
- package/dist/esm/queries/NullObservableQueryConnection.d.ts +2 -0
- package/dist/esm/queries/NullObservableQueryConnection.d.ts.map +1 -1
- package/dist/esm/queries/NullObservableQueryConnection.js +6 -0
- package/dist/esm/queries/NullObservableQueryConnection.js.map +1 -1
- package/dist/esm/queries/ObservableQueryConnection.d.ts +14 -1
- package/dist/esm/queries/ObservableQueryConnection.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryConnection.js +73 -2
- package/dist/esm/queries/ObservableQueryConnection.js.map +1 -1
- package/dist/esm/queries/WebSocketMessage.d.ts +11 -0
- package/dist/esm/queries/WebSocketMessage.d.ts.map +1 -0
- package/dist/esm/queries/WebSocketMessage.js +9 -0
- package/dist/esm/queries/WebSocketMessage.js.map +1 -0
- package/dist/esm/queries/index.d.ts +1 -0
- package/dist/esm/queries/index.d.ts.map +1 -1
- package/dist/esm/queries/index.js +1 -0
- package/dist/esm/queries/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/helpers/fetchHelper.ts +30 -0
- package/identity/IIdentityProvider.ts +4 -1
- package/identity/IdentityProvider.ts +14 -9
- package/identity/for_IdentityProvider/given/an_identity_provider.ts +4 -5
- package/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.ts +43 -0
- package/identity/for_IdentityProvider/when_refreshing/with_type_safe_details.ts +42 -0
- package/package.json +1 -1
- package/queries/IObservableQueryConnection.ts +10 -0
- package/queries/NullObservableQueryConnection.ts +10 -0
- package/queries/ObservableQueryConnection.ts +93 -2
- package/queries/WebSocketMessage.ts +44 -0
- package/queries/for_ObservableQueryConnection/given/an_observable_query_connection.ts +27 -0
- package/queries/for_ObservableQueryConnection/when_constructing.ts +15 -0
- package/queries/for_ObservableQueryFor/when_performing/with_enumerable_query.ts +5 -2
- package/queries/for_ObservableQueryFor/when_performing/with_paging.ts +5 -2
- package/queries/for_ObservableQueryFor/when_performing/with_parameter_descriptor_values.ts +5 -2
- package/queries/for_ObservableQueryFor/when_performing/with_partial_parameter_descriptor_values.ts +5 -2
- package/queries/for_ObservableQueryFor/when_performing/with_route_parameters_and_unused_parameters.ts +5 -2
- package/queries/for_ObservableQueryFor/when_performing/with_sorting.ts +5 -2
- package/queries/for_ObservableQueryFor/when_performing/with_valid_arguments.ts +7 -2
- package/queries/for_QueryFor/when_performing/with_abort_controller.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_enumerable_query.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_fetch_error.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_json_parse_error.ts +6 -3
- package/queries/for_QueryFor/when_performing/with_paging.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_parameter_descriptor_values.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_partial_parameter_descriptor_values.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_query_without_required_parameters.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_route_parameters_and_unused_parameters.ts +5 -2
- package/queries/for_QueryFor/when_performing/with_sorting.ts +7 -3
- package/queries/for_QueryFor/when_performing/with_valid_arguments.ts +6 -3
- package/queries/for_WebSocketMessage/when_creating_messages.ts +67 -0
- package/queries/index.ts +2 -1
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import sinon from 'sinon';
|
|
5
5
|
import { SomeCommand } from '../SomeCommand';
|
|
6
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
6
7
|
|
|
7
8
|
export class a_command {
|
|
8
9
|
command: SomeCommand;
|
|
9
10
|
fetchStub: sinon.SinonStub;
|
|
11
|
+
fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
|
|
10
12
|
|
|
11
13
|
constructor() {
|
|
12
14
|
this.command = new SomeCommand();
|
|
@@ -15,10 +17,7 @@ export class a_command {
|
|
|
15
17
|
this.command.setApiBasePath('/api');
|
|
16
18
|
this.command.someProperty = 'test-value';
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(globalThis.fetch as sinon.SinonStub).restore();
|
|
21
|
-
}
|
|
22
|
-
this.fetchStub = sinon.stub(globalThis, 'fetch');
|
|
20
|
+
this.fetchHelper = createFetchHelper();
|
|
21
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
23
22
|
}
|
|
24
23
|
}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
import sinon from 'sinon';
|
|
5
5
|
import { SomeCommand } from '../SomeCommand';
|
|
6
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
6
7
|
import { given } from '../../../given';
|
|
7
8
|
|
|
8
9
|
describe("when executing with custom http headers", given(class {
|
|
9
10
|
command: SomeCommand;
|
|
10
11
|
fetchStub: sinon.SinonStub;
|
|
12
|
+
fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
|
|
11
13
|
|
|
12
14
|
constructor() {
|
|
13
15
|
this.command = new SomeCommand();
|
|
@@ -19,7 +21,8 @@ describe("when executing with custom http headers", given(class {
|
|
|
19
21
|
'X-Custom-Header': 'custom-value',
|
|
20
22
|
'Authorization': 'Bearer token123'
|
|
21
23
|
}));
|
|
22
|
-
this.
|
|
24
|
+
this.fetchHelper = createFetchHelper();
|
|
25
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
23
26
|
}
|
|
24
27
|
}, context => {
|
|
25
28
|
const responseData = {
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
import sinon from 'sinon';
|
|
5
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
5
6
|
import { SomeCommand } from '../SomeCommand';
|
|
6
7
|
import { given } from '../../../given';
|
|
7
8
|
|
|
8
9
|
describe("when executing with origin and api base path", given(class {
|
|
9
10
|
command: SomeCommand;
|
|
10
11
|
fetchStub: sinon.SinonStub;
|
|
12
|
+
fetchHelper: { stubFetch: () => sinon.SinonStub; restore: () => void };
|
|
11
13
|
|
|
12
14
|
constructor() {
|
|
13
15
|
this.command = new SomeCommand();
|
|
@@ -15,7 +17,8 @@ describe("when executing with origin and api base path", given(class {
|
|
|
15
17
|
this.command.setOrigin('https://api.example.com');
|
|
16
18
|
this.command.setApiBasePath('/api/v1');
|
|
17
19
|
this.command.someProperty = 'test-value';
|
|
18
|
-
this.
|
|
20
|
+
this.fetchHelper = createFetchHelper();
|
|
21
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
19
22
|
}
|
|
20
23
|
}, context => {
|
|
21
24
|
const responseData = {
|
|
@@ -40,7 +43,7 @@ describe("when executing with origin and api base path", given(class {
|
|
|
40
43
|
});
|
|
41
44
|
|
|
42
45
|
afterEach(() => {
|
|
43
|
-
context.
|
|
46
|
+
context.fetchHelper.restore();
|
|
44
47
|
});
|
|
45
48
|
|
|
46
49
|
it("should_construct_url_with_origin_and_base_path", () => {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
import sinon from 'sinon';
|
|
5
|
+
import { createFetchHelper } from '../../../helpers/fetchHelper';
|
|
5
6
|
import { CommandWithRouteParams } from '../CommandWithRouteParams';
|
|
6
7
|
import { given } from '../../../given';
|
|
7
8
|
|
|
@@ -15,7 +16,8 @@ describe("when executing with route parameters", given(class {
|
|
|
15
16
|
this.command.setApiBasePath('/api');
|
|
16
17
|
this.command.id = '123';
|
|
17
18
|
this.command.name = 'Test Item';
|
|
18
|
-
this.
|
|
19
|
+
this.fetchHelper = createFetchHelper();
|
|
20
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
19
21
|
}
|
|
20
22
|
}, context => {
|
|
21
23
|
const responseData = {
|
|
@@ -40,7 +42,7 @@ describe("when executing with route parameters", given(class {
|
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
afterEach(() => {
|
|
43
|
-
context.
|
|
45
|
+
context.fetchHelper.restore();
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
it("should_replace_route_parameters_in_url", () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchHelper.d.ts","sourceRoot":"","sources":["../../../helpers/fetchHelper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,wBAAgB,iBAAiB;8BASH,KAAK,CAAC,SAAS;;EAY5C;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
1
2
|
import { IIdentity } from './IIdentity';
|
|
2
3
|
export declare abstract class IIdentityProvider {
|
|
3
|
-
abstract getCurrent<TDetails = object>(): Promise<IIdentity<TDetails>>;
|
|
4
|
+
abstract getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
4
5
|
}
|
|
5
6
|
//# sourceMappingURL=IIdentityProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/IIdentityProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxC,8BAAsB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"IIdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/IIdentityProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxC,8BAAsB,iBAAiB;IAQnC,QAAQ,CAAC,UAAU,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;CACpH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIdentityProvider.js","sources":["../../../identity/IIdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IIdentity } from './IIdentity';\n\n/**\n * Defines the identity provider.\n */\nexport abstract class IIdentityProvider {\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @returns The current identity as {@link IIdentity}.\n */\n abstract getCurrent<TDetails = object>(): Promise<IIdentity<TDetails>>;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"IIdentityProvider.js","sources":["../../../identity/IIdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentity } from './IIdentity';\n\n/**\n * Defines the identity provider.\n */\nexport abstract class IIdentityProvider {\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n abstract getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;\n}\n"],"names":[],"mappings":";;MASsB,iBAAiB,CAAA;AAStC;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
1
2
|
import { IIdentityProvider } from './IIdentityProvider';
|
|
2
3
|
import { IIdentity } from './IIdentity';
|
|
3
4
|
import { GetHttpHeaders } from 'GetHttpHeaders';
|
|
@@ -9,9 +10,9 @@ export declare class IdentityProvider extends IIdentityProvider {
|
|
|
9
10
|
static setHttpHeadersCallback(callback: GetHttpHeaders): void;
|
|
10
11
|
static setApiBasePath(apiBasePath: string): void;
|
|
11
12
|
static setOrigin(origin: string): void;
|
|
12
|
-
static getCurrent<TDetails = object>(): Promise<IIdentity<TDetails>>;
|
|
13
|
-
getCurrent<TDetails = object>(): Promise<IIdentity<TDetails>>;
|
|
14
|
-
static refresh<TDetails = object>(): Promise<IIdentity<TDetails>>;
|
|
13
|
+
static getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
14
|
+
getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
15
|
+
static refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>>;
|
|
15
16
|
private static getCookie;
|
|
16
17
|
private static clearCookie;
|
|
17
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/IdentityProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAOhD,qBAAa,gBAAiB,SAAQ,iBAAiB;IAEnD,MAAM,CAAC,QAAQ,CAAC,UAAU,sBAAsB;IAChD,MAAM,CAAC,mBAAmB,EAAE,c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AAW,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;WAIjG,OAAO,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAsBlH,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,WAAW;CAG7B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var fundamentals = require('@cratis/fundamentals');
|
|
3
4
|
var IIdentityProvider = require('./IIdentityProvider.js');
|
|
4
5
|
var Globals = require('../Globals.js');
|
|
5
6
|
var joinPaths = require('../joinPaths.js');
|
|
@@ -18,28 +19,29 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
|
|
|
18
19
|
static setOrigin(origin) {
|
|
19
20
|
IdentityProvider.origin = origin;
|
|
20
21
|
}
|
|
21
|
-
static async getCurrent() {
|
|
22
|
+
static async getCurrent(type) {
|
|
22
23
|
const cookie = this.getCookie();
|
|
23
24
|
if (cookie.length == 2) {
|
|
24
25
|
const json = atob(cookie[1]);
|
|
25
26
|
const result = JSON.parse(json);
|
|
27
|
+
const details = type ? fundamentals.JsonSerializer.deserializeFromInstance(type, result.details) : result.details;
|
|
26
28
|
return {
|
|
27
29
|
id: result.id,
|
|
28
30
|
name: result.name,
|
|
29
|
-
details:
|
|
31
|
+
details: details,
|
|
30
32
|
isSet: true,
|
|
31
|
-
refresh: IdentityProvider.refresh
|
|
33
|
+
refresh: () => IdentityProvider.refresh(type)
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
|
-
const identity = await this.refresh();
|
|
37
|
+
const identity = await this.refresh(type);
|
|
36
38
|
return identity;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
async getCurrent() {
|
|
40
|
-
return IdentityProvider.getCurrent();
|
|
41
|
+
async getCurrent(type) {
|
|
42
|
+
return IdentityProvider.getCurrent(type);
|
|
41
43
|
}
|
|
42
|
-
static async refresh() {
|
|
44
|
+
static async refresh(type) {
|
|
43
45
|
IdentityProvider.clearCookie();
|
|
44
46
|
const apiBasePath = IdentityProvider.apiBasePath || Globals.Globals.apiBasePath || '';
|
|
45
47
|
const url = joinPaths.joinPaths(apiBasePath, '/.cratis/me');
|
|
@@ -48,12 +50,13 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
|
|
|
48
50
|
headers: IdentityProvider.httpHeadersCallback?.() ?? {}
|
|
49
51
|
});
|
|
50
52
|
const result = await response.json();
|
|
53
|
+
const details = type ? fundamentals.JsonSerializer.deserializeFromInstance(type, result.details) : result.details;
|
|
51
54
|
return {
|
|
52
55
|
id: result.id,
|
|
53
56
|
name: result.name,
|
|
54
|
-
details:
|
|
57
|
+
details: details,
|
|
55
58
|
isSet: true,
|
|
56
|
-
refresh: IdentityProvider.refresh
|
|
59
|
+
refresh: () => IdentityProvider.refresh(type)
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
62
|
static getCookie() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from 'GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @returns The current identity as {@link IIdentity}.\n */\n static async getCurrent<TDetails = object>(): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n return {\n id: result.id,\n name: result.name,\n details:
|
|
1
|
+
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from 'GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n details: details as TDetails,\n isSet: true,\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearCookie();\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const url = joinPaths(apiBasePath, '/.cratis/me');\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n const result = await response.json() as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n\n return {\n id: result.id,\n name: result.name,\n details: details as TDetails,\n isSet: true,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n private static clearCookie() {\n document.cookie = `${IdentityPro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AAI,CAAC,CAAC,OAAO,CAAC,CAAA,EAAG,gBAAgB,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,CAAC;QACnF,IAAI,MAAM,EAAE;YACR,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;AAClC,YAAA,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACnD;AACA,QAAA,OAAO,EAAE;IACb;AAEQ,IAAA,OAAO,WAAW,GAAA;QACtB,QAAQ,CAAC,MAAM,GAAG,CAAA,EAAG,gBAAgB,CAAC,UAAU,yCAAyC;IAC7F;;;;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DataReceived } from './ObservableQueryConnection';
|
|
2
2
|
export interface IObservableQueryConnection<TDataType> {
|
|
3
|
+
readonly lastPingLatency: number;
|
|
4
|
+
readonly averageLatency: number;
|
|
3
5
|
connect(dataReceived: DataReceived<TDataType>, queryArguments?: object): void;
|
|
4
6
|
disconnect(): any;
|
|
5
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/IObservableQueryConnection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAK3D,MAAM,WAAW,0BAA0B,CAAC,SAAS;
|
|
1
|
+
{"version":3,"file":"IObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/IObservableQueryConnection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAK3D,MAAM,WAAW,0BAA0B,CAAC,SAAS;IAIjD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAKjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAOhC,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAK9E,UAAU,QAAG;CAChB"}
|
|
@@ -3,6 +3,8 @@ import { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
|
3
3
|
export declare class NullObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {
|
|
4
4
|
readonly defaultValue: TDataType;
|
|
5
5
|
constructor(defaultValue: TDataType);
|
|
6
|
+
get lastPingLatency(): number;
|
|
7
|
+
get averageLatency(): number;
|
|
6
8
|
connect(dataReceived: DataReceived<TDataType>): void;
|
|
7
9
|
disconnect(): void;
|
|
8
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NullObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/NullObservableQueryConnection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAO1E,qBAAa,6BAA6B,CAAC,SAAS,CAAE,YAAW,0BAA0B,CAAC,SAAS,CAAC;IAKtF,QAAQ,CAAC,YAAY,EAAE,SAAS;gBAAvB,YAAY,EAAE,SAAS;IAI5C,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC;IAM7C,UAAU;CAEb"}
|
|
1
|
+
{"version":3,"file":"NullObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/NullObservableQueryConnection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAO1E,qBAAa,6BAA6B,CAAC,SAAS,CAAE,YAAW,0BAA0B,CAAC,SAAS,CAAC;IAKtF,QAAQ,CAAC,YAAY,EAAE,SAAS;gBAAvB,YAAY,EAAE,SAAS;IAI5C,IAAI,eAAe,IAAI,MAAM,CAE5B;IAGD,IAAI,cAAc,IAAI,MAAM,CAE3B;IAGD,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC;IAM7C,UAAU;CAEb"}
|
|
@@ -7,6 +7,12 @@ class NullObservableQueryConnection {
|
|
|
7
7
|
constructor(defaultValue) {
|
|
8
8
|
this.defaultValue = defaultValue;
|
|
9
9
|
}
|
|
10
|
+
get lastPingLatency() {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
get averageLatency() {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
10
16
|
connect(dataReceived) {
|
|
11
17
|
dataReceived(QueryResult.QueryResult.empty(this.defaultValue));
|
|
12
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NullObservableQueryConnection.js","sources":["../../../queries/NullObservableQueryConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DataReceived } from './ObservableQueryConnection';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\n\n/**\n * Represents a {@link IObservableQueryConnection} when for instance one can't establish a connection.\n */\n\nexport class NullObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n /**\n * Initializes a new instance of the {@link NullObservableQueryConnection} class.\n * @param {TDataType} defaultValue The default value to serve.\n */\n constructor(readonly defaultValue: TDataType) {\n }\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>) {\n dataReceived(QueryResult.empty(this.defaultValue));\n }\n\n /** @inheritdoc */\n /* eslint-disable @typescript-eslint/no-empty-function */\n disconnect() {\n }\n}\n"],"names":["QueryResult"],"mappings":";;;;MAWa,6BAA6B,CAAA;AAKjB,IAAA,YAAA;AAArB,IAAA,WAAA,CAAqB,YAAuB,EAAA;QAAvB,IAAA,CAAA,YAAY,GAAZ,YAAY;IACjC;AAGA,IAAA,OAAO,CAAC,YAAqC,EAAA;QACzC,YAAY,CAACA,uBAAW,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD;IAIA,UAAU,GAAA;IACV;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"NullObservableQueryConnection.js","sources":["../../../queries/NullObservableQueryConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DataReceived } from './ObservableQueryConnection';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\n\n/**\n * Represents a {@link IObservableQueryConnection} when for instance one can't establish a connection.\n */\n\nexport class NullObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n /**\n * Initializes a new instance of the {@link NullObservableQueryConnection} class.\n * @param {TDataType} defaultValue The default value to serve.\n */\n constructor(readonly defaultValue: TDataType) {\n }\n\n /** @inheritdoc */\n get lastPingLatency(): number {\n return 0;\n }\n\n /** @inheritdoc */\n get averageLatency(): number {\n return 0;\n }\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>) {\n dataReceived(QueryResult.empty(this.defaultValue));\n }\n\n /** @inheritdoc */\n /* eslint-disable @typescript-eslint/no-empty-function */\n disconnect() {\n }\n}\n"],"names":["QueryResult"],"mappings":";;;;MAWa,6BAA6B,CAAA;AAKjB,IAAA,YAAA;AAArB,IAAA,WAAA,CAAqB,YAAuB,EAAA;QAAvB,IAAA,CAAA,YAAY,GAAZ,YAAY;IACjC;AAGA,IAAA,IAAI,eAAe,GAAA;AACf,QAAA,OAAO,CAAC;IACZ;AAGA,IAAA,IAAI,cAAc,GAAA;AACd,QAAA,OAAO,CAAC;IACZ;AAGA,IAAA,OAAO,CAAC,YAAqC,EAAA;QACzC,YAAY,CAACA,uBAAW,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD;IAIA,UAAU,GAAA;IACV;AACH;;;;"}
|
|
@@ -6,9 +6,22 @@ export declare class ObservableQueryConnection<TDataType> implements IObservable
|
|
|
6
6
|
private _socket;
|
|
7
7
|
private _disconnected;
|
|
8
8
|
private _url;
|
|
9
|
-
|
|
9
|
+
private _pingInterval?;
|
|
10
|
+
private _pingIntervalMs;
|
|
11
|
+
private _lastPingSentTime?;
|
|
12
|
+
private _lastPongLatency;
|
|
13
|
+
private _latencySamples;
|
|
14
|
+
private _connectionStartTime?;
|
|
15
|
+
constructor(url: URL, _microservice: string, pingIntervalMs?: number);
|
|
10
16
|
dispose(): void;
|
|
17
|
+
get lastPingLatency(): number;
|
|
18
|
+
get averageLatency(): number;
|
|
11
19
|
connect(dataReceived: DataReceived<TDataType>, queryArguments?: object): void;
|
|
12
20
|
disconnect(): void;
|
|
21
|
+
private startPinging;
|
|
22
|
+
private stopPinging;
|
|
23
|
+
private sendPing;
|
|
24
|
+
private handleMessage;
|
|
25
|
+
private handlePong;
|
|
13
26
|
}
|
|
14
27
|
//# sourceMappingURL=ObservableQueryConnection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryConnection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnection.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryConnection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAK7E,qBAAa,yBAAyB,CAAC,SAAS,CAAE,YAAW,0BAA0B,CAAC,SAAS,CAAC;IAkBxE,OAAO,CAAC,QAAQ,CAAC,aAAa;IAhBpD,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,aAAa,CAAC,CAAiC;IACvD,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,iBAAiB,CAAC,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,oBAAoB,CAAC,CAAS;gBAQ1B,GAAG,EAAE,GAAG,EAAmB,aAAa,EAAE,MAAM,EAAE,cAAc,GAAE,MAAc;IAkB5F,OAAO;IAOP,IAAI,eAAe,IAAI,MAAM,CAE5B;IAKD,IAAI,cAAc,IAAI,MAAM,CAM3B;IAGD,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM;IAmEtE,UAAU;IAYV,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,QAAQ;IAchB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,UAAU;CAYrB"}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Globals = require('../Globals.js');
|
|
4
|
+
var WebSocketMessage = require('./WebSocketMessage.js');
|
|
4
5
|
|
|
5
6
|
class ObservableQueryConnection {
|
|
6
7
|
_microservice;
|
|
7
8
|
_socket;
|
|
8
9
|
_disconnected = false;
|
|
9
10
|
_url;
|
|
10
|
-
|
|
11
|
+
_pingInterval;
|
|
12
|
+
_pingIntervalMs = 10000;
|
|
13
|
+
_lastPingSentTime;
|
|
14
|
+
_lastPongLatency = 0;
|
|
15
|
+
_latencySamples = [];
|
|
16
|
+
_connectionStartTime;
|
|
17
|
+
constructor(url, _microservice, pingIntervalMs = 10000) {
|
|
11
18
|
this._microservice = _microservice;
|
|
19
|
+
this._pingIntervalMs = pingIntervalMs;
|
|
12
20
|
const secure = url.protocol?.indexOf('https') === 0 || false;
|
|
13
21
|
this._url = `${secure ? 'wss' : 'ws'}://${url.host}${url.pathname}${url.search}`;
|
|
14
22
|
if (this._microservice?.length > 0) {
|
|
@@ -24,6 +32,16 @@ class ObservableQueryConnection {
|
|
|
24
32
|
dispose() {
|
|
25
33
|
this.disconnect();
|
|
26
34
|
}
|
|
35
|
+
get lastPingLatency() {
|
|
36
|
+
return this._lastPongLatency;
|
|
37
|
+
}
|
|
38
|
+
get averageLatency() {
|
|
39
|
+
if (this._latencySamples.length === 0) {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
const sum = this._latencySamples.reduce((acc, val) => acc + val, 0);
|
|
43
|
+
return sum / this._latencySamples.length;
|
|
44
|
+
}
|
|
27
45
|
connect(dataReceived, queryArguments) {
|
|
28
46
|
let url = this._url;
|
|
29
47
|
if (queryArguments) {
|
|
@@ -60,17 +78,21 @@ class ObservableQueryConnection {
|
|
|
60
78
|
console.log(`Connection for '${url}' established`);
|
|
61
79
|
timeToWait = 500;
|
|
62
80
|
currentAttempt = 0;
|
|
81
|
+
this._connectionStartTime = Date.now();
|
|
82
|
+
this.startPinging();
|
|
63
83
|
};
|
|
64
84
|
this._socket.onclose = () => {
|
|
65
85
|
if (this._disconnected)
|
|
66
86
|
return;
|
|
67
87
|
console.log(`Unexpected connection closed for route '${url}'`);
|
|
88
|
+
this.stopPinging();
|
|
68
89
|
retry();
|
|
69
90
|
};
|
|
70
91
|
this._socket.onerror = (error) => {
|
|
71
92
|
if (this._disconnected)
|
|
72
93
|
return;
|
|
73
94
|
console.log(`Error with connection for '${url}' - ${error}`);
|
|
95
|
+
this.stopPinging();
|
|
74
96
|
retry();
|
|
75
97
|
};
|
|
76
98
|
this._socket.onmessage = (ev) => {
|
|
@@ -78,7 +100,7 @@ class ObservableQueryConnection {
|
|
|
78
100
|
console.log('Received message after closing connection');
|
|
79
101
|
return;
|
|
80
102
|
}
|
|
81
|
-
|
|
103
|
+
this.handleMessage(ev.data, dataReceived);
|
|
82
104
|
};
|
|
83
105
|
};
|
|
84
106
|
if (this._disconnected)
|
|
@@ -91,10 +113,59 @@ class ObservableQueryConnection {
|
|
|
91
113
|
}
|
|
92
114
|
console.log(`Disconnecting '${this._url}'`);
|
|
93
115
|
this._disconnected = true;
|
|
116
|
+
this.stopPinging();
|
|
94
117
|
this._socket?.close();
|
|
95
118
|
console.log(`Connection for '${this._url}' closed`);
|
|
96
119
|
this._socket = undefined;
|
|
97
120
|
}
|
|
121
|
+
startPinging() {
|
|
122
|
+
this.stopPinging();
|
|
123
|
+
this._pingInterval = setInterval(() => {
|
|
124
|
+
this.sendPing();
|
|
125
|
+
}, this._pingIntervalMs);
|
|
126
|
+
}
|
|
127
|
+
stopPinging() {
|
|
128
|
+
if (this._pingInterval) {
|
|
129
|
+
clearInterval(this._pingInterval);
|
|
130
|
+
this._pingInterval = undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
sendPing() {
|
|
134
|
+
if (this._disconnected || !this._socket || this._socket.readyState !== WebSocket.OPEN) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this._lastPingSentTime = Date.now();
|
|
138
|
+
const pingMessage = {
|
|
139
|
+
type: WebSocketMessage.WebSocketMessageType.Ping,
|
|
140
|
+
timestamp: this._lastPingSentTime
|
|
141
|
+
};
|
|
142
|
+
this._socket.send(JSON.stringify(pingMessage));
|
|
143
|
+
}
|
|
144
|
+
handleMessage(rawData, dataReceived) {
|
|
145
|
+
try {
|
|
146
|
+
const message = JSON.parse(rawData);
|
|
147
|
+
if (message.type === WebSocketMessage.WebSocketMessageType.Pong) {
|
|
148
|
+
this.handlePong(message);
|
|
149
|
+
}
|
|
150
|
+
else if (message.type === WebSocketMessage.WebSocketMessageType.Data || !message.type) {
|
|
151
|
+
const data = message.data ?? message;
|
|
152
|
+
dataReceived(data);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error('Error parsing WebSocket message:', error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
handlePong(message) {
|
|
160
|
+
if (message.timestamp && this._lastPingSentTime) {
|
|
161
|
+
const latency = Date.now() - message.timestamp;
|
|
162
|
+
this._lastPongLatency = latency;
|
|
163
|
+
this._latencySamples.push(latency);
|
|
164
|
+
if (this._latencySamples.length > 100) {
|
|
165
|
+
this._latencySamples.shift();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
98
169
|
}
|
|
99
170
|
|
|
100
171
|
exports.ObservableQueryConnection = ObservableQueryConnection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryConnection.js","sources":["../../../queries/ObservableQueryConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Globals } from '../Globals';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\n\nexport type DataReceived<TDataType> = (data: QueryResult<TDataType>) => void;\n\n/**\n * Represents the connection for an observable query.\n */\nexport class ObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n\n private _socket!: WebSocket;\n private _disconnected = false;\n private _url: string;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryConnection<TDataType>} class.\n * @param {Url} url The fully qualified Url.\n */\n constructor(url: URL, private readonly _microservice: string) {\n const secure = url.protocol?.indexOf('https') === 0 || false;\n\n this._url = `${secure ? 'wss' : 'ws'}://${url.host}${url.pathname}${url.search}`;\n if (this._microservice?.length > 0) {\n const microserviceParam = `${Globals.microserviceWSQueryArgument}=${this._microservice}`;\n if (this._url.indexOf('?') > 0) {\n this._url = `${this._url}&${microserviceParam}`;\n } else {\n this._url = `${this._url}?${microserviceParam}`;\n }\n }\n }\n\n /**\n * Disposes the connection.\n */\n dispose() {\n this.disconnect();\n }\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>, queryArguments?: object) {\n let url = this._url;\n if (queryArguments) {\n if (url.indexOf('?') < 0) {\n url = `${url}?`;\n } else {\n url = `${url}&`;\n }\n const query = Object.keys(queryArguments).map(key => `${key}=${queryArguments[key]}`).join('&');\n url = `${url}${query}`;\n }\n\n let timeToWait = 500;\n const timeExponent = 500;\n const retries = 100;\n let currentAttempt = 0;\n const maxTime = 10_000;\n\n const connectSocket = () => {\n const retry = () => {\n currentAttempt++;\n if (currentAttempt > retries) {\n console.log(`Attempted ${retries} retries for route '${url}'. Abandoning.`);\n return;\n }\n console.log(`Attempting to reconnect for '${url}' (#${currentAttempt})`);\n\n setTimeout(connectSocket, timeToWait);\n timeToWait += (timeExponent * currentAttempt);\n timeToWait = timeToWait > maxTime ? maxTime : timeToWait; \n };\n\n this._socket = new WebSocket(url);\n this._socket.onopen = () => {\n if (this._disconnected) return;\n console.log(`Connection for '${url}' established`);\n timeToWait = 500;\n currentAttempt = 0;\n };\n this._socket.onclose = () => {\n if (this._disconnected) return;\n console.log(`Unexpected connection closed for route '${url}'`);\n retry();\n };\n this._socket.onerror = (error) => {\n if (this._disconnected) return;\n console.log(`Error with connection for '${url}' - ${error}`);\n retry();\n };\n this._socket.onmessage = (ev) => {\n if (this._disconnected) {\n console.log('Received message after closing connection');\n return;\n }\n dataReceived(JSON.parse(ev.data));\n };\n };\n\n if (this._disconnected) return;\n connectSocket();\n }\n\n /** @inheritdoc */\n disconnect() {\n if (this._disconnected) {\n return;\n }\n console.log(`Disconnecting '${this._url}'`);\n this._disconnected = true;\n this._socket?.close();\n console.log(`Connection for '${this._url}' closed`);\n this._socket = undefined!;\n }\n}\n"],"names":["Globals"],"mappings":";;;;MAYa,yBAAyB,CAAA;AAUK,IAAA,aAAA;AAR/B,IAAA,OAAO;IACP,aAAa,GAAG,KAAK;AACrB,IAAA,IAAI;IAMZ,WAAA,CAAY,GAAQ,EAAmB,aAAqB,EAAA;QAArB,IAAA,CAAA,aAAa,GAAb,aAAa;AAChD,QAAA,MAAM,MAA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E;AACxB,gBAAA,OAAO,CAAC,GAAG,CAAC,2CAA2C,GAAG,CAAA,CAAA,CAAG,CAAC;AAC9D,gBAAA,KAAK,EAAE;AACX,YAAA,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,CAAC,KAAK,KAAI;gBAC7B,IAAI,IAAI,CAAC,aAAa;oBAAE;gBACxB,OAAO,CAAC,GAAG,CAAC,CAAA,2BAAA,EAA8B,GAAG,CAAA,IAAA,EAAO,KAAK,CAAA,CAAE,CAAC;AAC5D,gBAAA,KAAK,EAAE;AACX,YAAA,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,EAAE,KAAI;AAC5B,gBAAA,IAAI,IAAI,CAAC,aAAa,EAAE;AACpB,oBAAA,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC;oBACxD;gBACJ;gBACA,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AACrC,YAAA,CAAC;AACL,QAAA,CAAC;QAED,IAAI,IAAI,CAAC,aAAa;YAAE;AACxB,QAAA,aAAa,EAAE;IACnB;IAGA,UAAU,GAAA;AACN,QAAA,IAAI,IAAI,CAAC,aAAa,EAAE;YACpB;QACJ;QACA,OAAO,CAAC,GAAG,CAAC,CAAA,eAAA,EAAkB,IAAI,CAAC,IAAI,CAAA,CAAA,CAAG,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI;AACzB,QAAA,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE;QACrB,OAAO,CAAC,GAAG,CAAC,CAAA,gBAAA,EAAmB,IAAI,CAAC,IAAI,CAAA,QAAA,CAAU,CAAC;AACnD,QAAA,IAAI,CAAC,OAAO,GAAG,SAAU;IAC7B;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"ObservableQueryConnection.js","sources":["../../../queries/ObservableQueryConnection.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Globals } from '../Globals';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\nimport { WebSocketMessage, WebSocketMessageType } from './WebSocketMessage';\n\nexport type DataReceived<TDataType> = (data: QueryResult<TDataType>) => void;\n\n/**\n * Represents the connection for an observable query.\n */\nexport class ObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n\n private _socket!: WebSocket;\n private _disconnected = false;\n private _url: string;\n private _pingInterval?: ReturnType<typeof setInterval>;\n private _pingIntervalMs: number = 10000;\n private _lastPingSentTime?: number;\n private _lastPongLatency: number = 0;\n private _latencySamples: number[] = [];\n private _connectionStartTime?: number;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryConnection<TDataType>} class.\n * @param {Url} url The fully qualified Url.\n * @param {string} _microservice The microservice name.\n * @param {number} pingIntervalMs The ping interval in milliseconds (default: 10000).\n */\n constructor(url: URL, private readonly _microservice: string, pingIntervalMs: number = 10000) {\n this._pingIntervalMs = pingIntervalMs;\n const secure = url.protocol?.indexOf('https') === 0 || false;\n\n this._url = `${secure ? 'wss' : 'ws'}://${url.host}${url.pathname}${url.search}`;\n if (this._microservice?.length > 0) {\n const microserviceParam = `${Globals.microserviceWSQueryArgument}=${this._microservice}`;\n if (this._url.indexOf('?') > 0) {\n this._url = `${this._url}&${microserviceParam}`;\n } else {\n this._url = `${this._url}?${microserviceParam}`;\n }\n }\n }\n\n /**\n * Disposes the connection.\n */\n dispose() {\n this.disconnect();\n }\n\n /**\n * Gets the latency of the last ping/pong sequence in milliseconds.\n */\n get lastPingLatency(): number {\n return this._lastPongLatency;\n }\n\n /**\n * Gets the average latency since the connection started in milliseconds.\n */\n get averageLatency(): number {\n if (this._latencySamples.length === 0) {\n return 0;\n }\n const sum = this._latencySamples.reduce((acc, val) => acc + val, 0);\n return sum / this._latencySamples.length;\n }\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>, queryArguments?: object) {\n let url = this._url;\n if (queryArguments) {\n if (url.indexOf('?') < 0) {\n url = `${url}?`;\n } else {\n url = `${url}&`;\n }\n const query = Object.keys(queryArguments).map(key => `${key}=${queryArguments[key]}`).join('&');\n url = `${url}${query}`;\n }\n\n let timeToWait = 500;\n const timeExponent = 500;\n const retries = 100;\n let currentAttempt = 0;\n const maxTime = 10_000;\n\n const connectSocket = () => {\n const retry = () => {\n currentAttempt++;\n if (currentAttempt > retries) {\n console.log(`Attempted ${retries} retries for route '${url}'. Abandoning.`);\n return;\n }\n console.log(`Attempting to reconnect for '${url}' (#${currentAttempt})`);\n\n setTimeout(connectSocket, timeToWait);\n timeToWait += (timeExponent * currentAttempt);\n timeToWait = timeToWait > maxTime ? maxTime : timeToWait; \n };\n\n this._socket = new WebSocket(url);\n this._socket.onopen = () => {\n if (this._disconnected) return;\n console.log(`Connection for '${url}' established`);\n timeToWait = 500;\n currentAttempt = 0;\n this._connectionStartTime = Date.now();\n this.startPinging();\n };\n this._socket.onclose = () => {\n if (this._disconnected) return;\n console.log(`Unexpected connection closed for route '${url}'`);\n this.stopPinging();\n retry();\n };\n this._socket.onerror = (error) => {\n if (this._disconnected) return;\n console.log(`Error with connection for '${url}' - ${error}`);\n this.stopPinging();\n retry();\n };\n this._socket.onmessage = (ev) => {\n if (this._disconnected) {\n console.log('Received message after closing connection');\n return;\n }\n this.handleMessage(ev.data, dataReceived);\n };\n };\n\n if (this._disconnected) return;\n connectSocket();\n }\n\n /** @inheritdoc */\n disconnect() {\n if (this._disconnected) {\n return;\n }\n console.log(`Disconnecting '${this._url}'`);\n this._disconnected = true;\n this.stopPinging();\n this._socket?.close();\n console.log(`Connection for '${this._url}' closed`);\n this._socket = undefined!;\n }\n\n private startPinging() {\n this.stopPinging();\n this._pingInterval = setInterval(() => {\n this.sendPing();\n }, this._pingIntervalMs);\n }\n\n private stopPinging() {\n if (this._pingInterval) {\n clearInterval(this._pingInterval);\n this._pingInterval = undefined;\n }\n }\n\n private sendPing() {\n if (this._disconnected || !this._socket || this._socket.readyState !== WebSocket.OPEN) {\n return;\n }\n\n this._lastPingSentTime = Date.now();\n const pingMessage: WebSocketMessage = {\n type: WebSocketMessageType.Ping,\n timestamp: this._lastPingSentTime\n };\n\n this._socket.send(JSON.stringify(pingMessage));\n }\n\n private handleMessage(rawData: string, dataReceived: DataReceived<TDataType>) {\n try {\n const message = JSON.parse(rawData) as WebSocketMessage;\n\n // Handle messages based on type\n if (message.type === WebSocketMessageType.Pong) {\n this.handlePong(message);\n } else if (message.type === WebSocketMessageType.Data || !message.type) {\n // For backward compatibility, treat messages without a type as data messages\n const data = message.data ?? message;\n dataReceived(data as QueryResult<TDataType>);\n }\n } catch (error) {\n console.error('Error parsing WebSocket message:', error);\n }\n }\n\n private handlePong(message: WebSocketMessage) {\n if (message.timestamp && this._lastPingSentTime) {\n const latency = Date.now() - message.timestamp;\n this._lastPongLatency = latency;\n this._latencySamples.push(latency);\n\n // Keep only the last 100 samples for average calculation\n if (this._latencySamples.length > 100) {\n this._latencySamples.shift();\n }\n }\n }\n}\n"],"names":["Globals","WebSocketMessageType"],"mappings":";;;;;MAaa,yBAAyB,CAAA;AAkBK,IAAA,aAAA;AAhB/B,IAAA,OAAO;IACP,aAAa,GAAG,KAAK;AACrB,IAAA,IAAI;AACJ,IAAA,aAAa;IACb,eAAe,GAAW,KAAK;AAC/B,IAAA,iBAAiB;IACjB,gBAAgB,GAAW,CAAC;IAC5B,eAAe,GAAa,EAAE;AAC9B,IAAA,oBAAoB;AAQ5B,IAAA,WAAA,CAAY,GAAQ,EAAmB,aAAqB,EAAE,iBAAyB,KAAK,EAAA;QAArD,IAAA,CAAA,aAAa,GAAb,aAAa;AAChD,QAAA,IAAI,CAAC,eAAe,GAAG,cAAc;AACrC,QAAA,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK;QAE5D,IAAI,CAAC,IAAI,GAAG,CAAA,EAAG,MAAM,G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|
+
|
|
3
|
+
exports.WebSocketMessageType = void 0;
|
|
4
|
+
(function (WebSocketMessageType) {
|
|
5
|
+
WebSocketMessageType["Data"] = "Data";
|
|
6
|
+
WebSocketMessageType["Ping"] = "Ping";
|
|
7
|
+
WebSocketMessageType["Pong"] = "Pong";
|
|
8
|
+
})(exports.WebSocketMessageType || (exports.WebSocketMessageType = {}));
|
|
9
|
+
//# sourceMappingURL=WebSocketMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketMessage.js","sources":["../../../queries/WebSocketMessage.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Represents the type of WebSocket message.\n */\nexport enum WebSocketMessageType {\n /**\n * A data message containing query results.\n */\n Data = 'Data',\n\n /**\n * A ping message sent from client to server.\n */\n Ping = 'Ping',\n\n /**\n * A pong message sent from server to client in response to a ping.\n */\n Pong = 'Pong'\n}\n\n/**\n * Represents a WebSocket message envelope.\n */\nexport type WebSocketMessage = {\n /**\n * The type of message.\n */\n type: WebSocketMessageType;\n\n /**\n * The timestamp when the message was sent (for ping/pong latency tracking).\n */\n timestamp?: number;\n\n /**\n * The payload data (for data messages).\n */\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data?: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n};\n"],"names":["WebSocketMessageType"],"mappings":";;AAMYA;AAAZ,CAAA,UAAY,oBAAoB,EAAA;AAI5B,IAAA,oBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AAKb,IAAA,oBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AAKb,IAAA,oBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACjB,CAAC,EAfWA,4BAAoB,KAApBA,4BAAoB,GAAA,EAAA,CAAA,CAAA;;"}
|
|
@@ -14,6 +14,7 @@ export * from './ObservableQueryFor';
|
|
|
14
14
|
export * from './IObservableQueryConnection';
|
|
15
15
|
export * from './ObservableQueryConnection';
|
|
16
16
|
export * from './ObservableQuerySubscription';
|
|
17
|
+
export * from './WebSocketMessage';
|
|
17
18
|
export * from './IQueryProvider';
|
|
18
19
|
export * from './QueryProvider';
|
|
19
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../queries/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../queries/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
@@ -12,6 +12,7 @@ var QueryResultWithState = require('./QueryResultWithState.js');
|
|
|
12
12
|
var ObservableQueryFor = require('./ObservableQueryFor.js');
|
|
13
13
|
var ObservableQueryConnection = require('./ObservableQueryConnection.js');
|
|
14
14
|
var ObservableQuerySubscription = require('./ObservableQuerySubscription.js');
|
|
15
|
+
var WebSocketMessage = require('./WebSocketMessage.js');
|
|
15
16
|
var IQueryProvider = require('./IQueryProvider.js');
|
|
16
17
|
var QueryProvider = require('./QueryProvider.js');
|
|
17
18
|
|
|
@@ -32,6 +33,10 @@ exports.QueryResultWithState = QueryResultWithState.QueryResultWithState;
|
|
|
32
33
|
exports.ObservableQueryFor = ObservableQueryFor.ObservableQueryFor;
|
|
33
34
|
exports.ObservableQueryConnection = ObservableQueryConnection.ObservableQueryConnection;
|
|
34
35
|
exports.ObservableQuerySubscription = ObservableQuerySubscription.ObservableQuerySubscription;
|
|
36
|
+
Object.defineProperty(exports, "WebSocketMessageType", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return WebSocketMessage.WebSocketMessageType; }
|
|
39
|
+
});
|
|
35
40
|
exports.IQueryProvider = IQueryProvider.IQueryProvider;
|
|
36
41
|
exports.QueryProvider = QueryProvider.QueryProvider;
|
|
37
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|