@cratis/arc 20.63.0 → 20.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/EventSourceFactory.ts +12 -0
  2. package/Globals.ts +8 -0
  3. package/dist/cjs/Globals.js.map +1 -1
  4. package/dist/cjs/queries/ServerSentEventHubConnection.js +1 -1
  5. package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -1
  6. package/dist/cjs/queries/ServerSentEventQueryConnection.js +6 -3
  7. package/dist/cjs/queries/ServerSentEventQueryConnection.js.map +1 -1
  8. package/dist/esm/EventSourceFactory.d.ts +2 -0
  9. package/dist/esm/EventSourceFactory.d.ts.map +1 -0
  10. package/dist/esm/EventSourceFactory.js +2 -0
  11. package/dist/esm/EventSourceFactory.js.map +1 -0
  12. package/dist/esm/Globals.d.ts +2 -0
  13. package/dist/esm/Globals.d.ts.map +1 -1
  14. package/dist/esm/Globals.js.map +1 -1
  15. package/dist/esm/index.d.ts +1 -0
  16. package/dist/esm/index.d.ts.map +1 -1
  17. package/dist/esm/queries/ServerSentEventHubConnection.js +1 -1
  18. package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -1
  19. package/dist/esm/queries/ServerSentEventQueryConnection.d.ts.map +1 -1
  20. package/dist/esm/queries/ServerSentEventQueryConnection.js +6 -3
  21. package/dist/esm/queries/ServerSentEventQueryConnection.js.map +1 -1
  22. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.d.ts +2 -0
  23. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.d.ts.map +1 -0
  24. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.js +38 -0
  25. package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.js.map +1 -0
  26. package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.d.ts +2 -0
  27. package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.d.ts.map +1 -0
  28. package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.js +43 -0
  29. package/dist/esm/queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.js.map +1 -0
  30. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  31. package/index.ts +1 -0
  32. package/package.json +1 -1
  33. package/queries/ServerSentEventHubConnection.ts +1 -1
  34. package/queries/ServerSentEventQueryConnection.ts +5 -3
  35. package/queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.ts +57 -0
  36. package/queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.ts +63 -0
@@ -1 +1 @@
1
- {"version":3,"file":"ServerSentEventQueryConnection.js","sources":["../../../queries/ServerSentEventQueryConnection.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 { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { DataReceived } from './ObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\n\n/**\n * The SSE demultiplexer route used when connecting through the multiplexed observable query endpoint.\n */\nexport const SSE_HUB_ROUTE = '/.cratis/queries/sse';\n\n/**\n * Represents a direct Server-Sent Events (SSE) connection for a single observable query.\n *\n * In direct mode the URL points to the per-query endpoint (e.g. `/api/queries/latest`).\n * The backend detects the `Accept: text/event-stream` header and streams results directly.\n *\n * The caller (typically {@link createObservableQueryConnection}) decides which URL to use;\n * this class is transport-agnostic beyond being SSE.\n */\nexport class ServerSentEventQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n private _eventSource?: EventSource;\n private _disconnected = false;\n\n /** @inheritdoc */\n readonly lastPingLatency: number = 0;\n\n /** @inheritdoc */\n readonly averageLatency: number = 0;\n\n /**\n * Initializes a new instance of {@link ServerSentEventQueryConnection}.\n * @param {URL} url The fully qualified URL of the SSE endpoint (including query parameters).\n */\n constructor(private readonly _url: URL) {}\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>, queryArguments?: object): void {\n if (this._disconnected) return;\n\n // Guard against environments where EventSource is not available (e.g. Node.js, SSR).\n if (typeof EventSource === 'undefined') {\n return;\n }\n\n let url = this._url.toString();\n if (queryArguments) {\n const separator = url.includes('?') ? '&' : '?';\n const query = Object.entries(queryArguments)\n .filter(([, value]) => value !== undefined && value !== null)\n .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)\n .join('&');\n if (query) {\n url = `${url}${separator}${query}`;\n }\n }\n\n this._eventSource = new EventSource(url);\n\n this._eventSource.onmessage = (event: MessageEvent) => {\n if (this._disconnected) return;\n try {\n const result = JSON.parse(event.data as string) as QueryResult<TDataType>;\n dataReceived(result);\n } catch (error) {\n console.error('SSE: error parsing message', error);\n }\n };\n\n this._eventSource.onerror = () => {\n if (this._disconnected) return;\n console.warn(`SSE: connection error for '${url}', EventSource will retry automatically.`);\n };\n }\n\n /** @inheritdoc */\n disconnect(): void {\n if (this._disconnected) return;\n this._disconnected = true;\n this._eventSource?.close();\n this._eventSource = undefined;\n }\n}\n"],"names":["SSE_HUB_ROUTE","ServerSentEventQueryConnection","_eventSource","_disconnected","lastPingLatency","averageLatency","_url","connect","dataReceived","queryArguments","EventSource","url","toString","separator","includes","query","Object","entries","filter","value","undefined","map","key","encodeURIComponent","String","join","onmessage","event","result","JSON","parse","data","error","console","onerror","warn","disconnect","close"],"mappings":"AAAA;AACA;AAMA;;IAGO,MAAMA,aAAAA,GAAgB;AAE7B;;;;;;;;AAQC,IACM,MAAMC,8BAAAA,CAAAA;;IACDC,YAAAA;AACAC,IAAAA,aAAAA,GAAgB,KAAA;uBAGxB,eAASC,GAA0B,CAAA;uBAGnC,cAASC,GAAyB,CAAA;AAElC;;;QAIA,WAAA,CAAY,IAA0B,CAAE;aAAXC,IAAAA,GAAAA,IAAAA;AAAY,IAAA;AAEzC,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AAAA,EAAO;gBACZC,OAAAA,CAAQD,KAAK,CAAC,4BAAA,EAA8BA,KAAAA,CAAAA;AAChD,YAAA;AACJ,QAAA,CAAA;AAEA,QAAA,IAAI,CAAC9B,YAAY,CAACgC,OAAO,GAAG,IAAA;YACxB,IAAI,IAAI,CAAC/B,aAAa,EAAE;AACxB8B,YAAAA,OAAAA,CAAQE,IAAI,CAAC,CAAC,2BAA2B,EAAExB,GAAAA,CAAI,wCAAwC,CAAC,CAAA;AAC5F,QAAA,CAAA;AACJ,IAAA;AAEA,uBACAyB,UAAAA,GAAmB;QACf,IAAI,IAAI,CAACjC,aAAa,EAAE;QACxB,IAAI,CAACA,aAAa,GAAG,IAAA;QACrB,IAAI,CAACD,YAAY,EAAEmC,KAAAA,EAAAA;QACnB,IAAI,CAACnC,YAAY,GAAGkB,SAAAA;AACxB,IAAA;AACJ;;;;"}
1
+ {"version":3,"file":"ServerSentEventQueryConnection.js","sources":["../../../queries/ServerSentEventQueryConnection.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 { DataReceived } from './ObservableQueryConnection';\nimport { QueryResult } from './QueryResult';\n\n/**\n * The SSE demultiplexer route used when connecting through the multiplexed observable query endpoint.\n */\nexport const SSE_HUB_ROUTE = '/.cratis/queries/sse';\n\n/**\n * Represents a direct Server-Sent Events (SSE) connection for a single observable query.\n *\n * In direct mode the URL points to the per-query endpoint (e.g. `/api/queries/latest`).\n * The backend detects the `Accept: text/event-stream` header and streams results directly.\n *\n * The caller (typically {@link createObservableQueryConnection}) decides which URL to use;\n * this class is transport-agnostic beyond being SSE.\n */\nexport class ServerSentEventQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {\n private _eventSource?: EventSource;\n private _disconnected = false;\n\n /** @inheritdoc */\n readonly lastPingLatency: number = 0;\n\n /** @inheritdoc */\n readonly averageLatency: number = 0;\n\n /**\n * Initializes a new instance of {@link ServerSentEventQueryConnection}.\n * @param {URL} url The fully qualified URL of the SSE endpoint (including query parameters).\n */\n constructor(private readonly _url: URL) {}\n\n /** @inheritdoc */\n connect(dataReceived: DataReceived<TDataType>, queryArguments?: object): void {\n if (this._disconnected) return;\n\n // Guard against environments where EventSource is not available (e.g. Node.js, SSR)\n // and no custom factory has been supplied to substitute it.\n if (!Globals.eventSourceFactory && typeof EventSource === 'undefined') {\n return;\n }\n\n let url = this._url.toString();\n if (queryArguments) {\n const separator = url.includes('?') ? '&' : '?';\n const query = Object.entries(queryArguments)\n .filter(([, value]) => value !== undefined && value !== null)\n .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)\n .join('&');\n if (query) {\n url = `${url}${separator}${query}`;\n }\n }\n\n this._eventSource = Globals.eventSourceFactory ? Globals.eventSourceFactory(url) : new EventSource(url);\n\n this._eventSource.onmessage = (event: MessageEvent) => {\n if (this._disconnected) return;\n try {\n const result = JSON.parse(event.data as string) as QueryResult<TDataType>;\n dataReceived(result);\n } catch (error) {\n console.error('SSE: error parsing message', error);\n }\n };\n\n this._eventSource.onerror = () => {\n if (this._disconnected) return;\n console.warn(`SSE: connection error for '${url}', EventSource will retry automatically.`);\n };\n }\n\n /** @inheritdoc */\n disconnect(): void {\n if (this._disconnected) return;\n this._disconnected = true;\n this._eventSource?.close();\n this._eventSource = undefined;\n }\n}\n"],"names":["SSE_HUB_ROUTE","ServerSentEventQueryConnection","_eventSource","_disconnected","lastPingLatency","averageLatency","_url","connect","dataReceived","queryArguments","Globals","eventSourceFactory","EventSource","url","toString","separator","includes","query","Object","entries","filter","value","undefined","map","key","encodeURIComponent","String","join","onmessage","event","result","JSON","parse","data","error","console","onerror","warn","disconnect","close"],"mappings":";;AAAA;AACA;AAOA;;IAGO,MAAMA,aAAAA,GAAgB;AAE7B;;;;;;;;AAQC,IACM,MAAMC,8BAAAA,CAAAA;;IACDC,YAAAA;AACAC,IA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AAA,CAAAA;AAEnG,QAAA,IAAI,CAACX,YAAY,CAAC0B,SAAS,GAAG,CAACC,KAAAA,GAAAA;YAC3B,IAAI,IAAI,CAAC1B,aAAa,EAAE;YACxB,IAAI;AACA,gBAAA,MAAM2B,MAAAA,GAASC,IAAAA,CAAKC,KAAK,CAACH,MAAMI,IAAI,CAAA;gBACpCzB,YAAAA,CAAasB,MAAAA,CAAAA;AACjB,YAAA,CAAA,CAAE,OAAOI,KAAAA,EAAO;gBACZC,OAAAA,CAAQD,KAAK,CAAC,4BAAA,EAA8BA,KAAAA,CAAAA;AAChD,YAAA;AACJ,QAAA,CAAA;AAEA,QAAA,IAAI,CAAChC,YAAY,CAACkC,OAAO,GAAG,IAAA;YACxB,IAAI,IAAI,CAACjC,aAAa,EAAE;AACxBgC,YAAAA,OAAAA,CAAQE,IAAI,CAAC,CAAC,2BAA2B,EAAExB,GAAAA,CAAI,wCAAwC,CAAC,CAAA;AAC5F,QAAA,CAAA;AACJ,IAAA;AAEA,uBACAyB,UAAAA,GAAmB;QACf,IAAI,IAAI,CAACnC,aAAa,EAAE;QACxB,IAAI,CAACA,aAAa,GAAG,IAAA;QACrB,IAAI,CAACD,YAAY,EAAEqC,KAAAA,EAAAA;QACnB,IAAI,CAACrC,YAAY,GAAGoB,SAAAA;AACxB,IAAA;AACJ;;;;"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=uses_custom_event_source_factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uses_custom_event_source_factory.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ import sinon from 'sinon';
2
+ import { Globals } from '../../../Globals';
3
+ import { a_server_sent_event_hub_connection } from '../given/a_server_sent_event_hub_connection';
4
+ import { given } from '../../../given';
5
+ import { HubMessageType } from '../../WebSocketHubConnection';
6
+ describe('when subscribing with a custom event source factory configured', given(a_server_sent_event_hub_connection, context => {
7
+ let customEventSource;
8
+ let factoryStub;
9
+ let originalFactory;
10
+ beforeEach(() => {
11
+ originalFactory = Globals.eventSourceFactory;
12
+ customEventSource = {
13
+ onopen: null,
14
+ onmessage: null,
15
+ onerror: null,
16
+ close: sinon.stub(),
17
+ readyState: 1,
18
+ };
19
+ factoryStub = sinon.stub().returns(customEventSource);
20
+ Globals.eventSourceFactory = factoryStub;
21
+ context.setup();
22
+ context.connection.subscribe('q1', { queryName: 'MyQuery' }, sinon.stub());
23
+ });
24
+ afterEach(() => {
25
+ Globals.eventSourceFactory = originalFactory;
26
+ sinon.restore();
27
+ });
28
+ it('should call the custom factory with the SSE hub url', () => factoryStub.calledOnce.should.be.true);
29
+ it('should pass the hub url to the factory', () => factoryStub.getCall(0).args[0].should.equal('http://localhost/.cratis/queries/sse'));
30
+ it('should not use the default global EventSource', () => (context.fakeEventSource.onopen === null).should.be.true);
31
+ describe('when the custom event source receives the Connected message', () => {
32
+ beforeEach(() => {
33
+ customEventSource.onmessage({ data: JSON.stringify({ type: HubMessageType.Connected, payload: 'conn-1' }) });
34
+ });
35
+ it('should record the connection as open', () => context.connection.isConnected.should.be.true);
36
+ });
37
+ }));
38
+ //# sourceMappingURL=uses_custom_event_source_factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uses_custom_event_source_factory.js","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventHubConnection/when_subscribing/uses_custom_event_source_factory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAC;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAU9D,QAAQ,CAAC,gEAAgE,EAAE,KAAK,CAAC,kCAAk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AC,CAAC;IAEpH,QAAQ,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACzE,UAAU,CAAC,GAAG,EAAE;YACZ,iBAAiB,CAAC,SAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAkB,CAAC,CAAC;QAClI,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=with_custom_event_source_factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with_custom_event_source_factory.d.ts","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import sinon from 'sinon';
2
+ import { Globals } from '../../../Globals';
3
+ import { ServerSentEventQueryConnection } from '../../ServerSentEventQueryConnection';
4
+ describe('when connecting with a custom event source factory configured and no global EventSource available', () => {
5
+ let originalEventSource;
6
+ let originalFactory;
7
+ let fakeEventSource;
8
+ let factoryStub;
9
+ let connection;
10
+ let receivedData;
11
+ beforeEach(() => {
12
+ originalEventSource = globalThis['EventSource'];
13
+ delete globalThis['EventSource'];
14
+ originalFactory = Globals.eventSourceFactory;
15
+ fakeEventSource = {
16
+ onmessage: null,
17
+ onerror: null,
18
+ close: sinon.stub(),
19
+ };
20
+ factoryStub = sinon.stub().returns(fakeEventSource);
21
+ Globals.eventSourceFactory = factoryStub;
22
+ receivedData = [];
23
+ connection = new ServerSentEventQueryConnection(new URL('http://localhost/.cratis/queries/sse?query=Test'));
24
+ connection.connect((result) => receivedData.push(result));
25
+ });
26
+ afterEach(() => {
27
+ if (originalEventSource !== undefined) {
28
+ globalThis['EventSource'] = originalEventSource;
29
+ }
30
+ Globals.eventSourceFactory = originalFactory;
31
+ sinon.restore();
32
+ });
33
+ it('should call the custom factory instead of the global EventSource constructor', () => factoryStub.calledOnce.should.be.true);
34
+ it('should pass the connection url to the factory', () => factoryStub.getCall(0).args[0].should.contain('/.cratis/queries/sse'));
35
+ describe('when a message arrives on the custom event source', () => {
36
+ const result = { data: ['a', 'b'], isSuccess: true, isAuthorized: true, isValid: true, hasExceptions: false, hasData: true, validationResults: [], exceptionMessages: [], exceptionStackTrace: '', paging: { page: 0, size: 0, totalItems: 0, totalPages: 0 } };
37
+ beforeEach(() => {
38
+ fakeEventSource.onmessage({ data: JSON.stringify(result) });
39
+ });
40
+ it('should deliver the payload to the callback', () => receivedData.length.should.equal(1));
41
+ });
42
+ });
43
+ //# sourceMappingURL=with_custom_event_source_factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with_custom_event_source_factory.js","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventQueryConnection/when_connecting/with_custom_event_source_factory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAStF,QAAQ,CAAC,mGAAmG,EAAE,GAAG,EAAE;IAC/G,IAAI,mBAAuC,CAAC;IAC5C,IAAI,eAA+C,CAAC;IACpD,IAAI,eAAgC,CAAC;IACrC,IAAI,WAA4B,CAAC;IACjC,IAAI,UAAoD,CAAC;IACzD,IAAI,YAAqC,CAAC;IAE1C,UAAU,CAAC,GAAG,EAAE;QACZ,mBAAmB,GAAI,UAAsC,CAAC,aAAa,CAAuB,CAAC;QACnG,OAAQ,UAAsC,CAAC,aAAa,CAAC,CAAC;QAE9D,eAAe,GAAG,OAAO,CAAC,kB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