@cratis/arc 22.0.1 → 22.0.2

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 (24) hide show
  1. package/dist/cjs/queries/ObservableQueryFor.js +3 -3
  2. package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
  3. package/dist/esm/queries/ObservableQueryFor.d.ts +6 -6
  4. package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
  5. package/dist/esm/queries/ObservableQueryFor.js +3 -3
  6. package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
  7. package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.d.ts +17 -0
  8. package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.d.ts.map +1 -1
  9. package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.js +34 -0
  10. package/dist/esm/queries/for_ObservableQueryFor/given/TestQueries.js.map +1 -1
  11. package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.d.ts +2 -1
  12. package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.d.ts.map +1 -1
  13. package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.js +3 -1
  14. package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_for.js.map +1 -1
  15. package/dist/esm/queries/for_ObservableQueryFor/when_receiving_a_result/and_the_model_has_a_calendar_collection.d.ts +2 -0
  16. package/dist/esm/queries/for_ObservableQueryFor/when_receiving_a_result/and_the_model_has_a_calendar_collection.d.ts.map +1 -0
  17. package/dist/esm/queries/for_ObservableQueryFor/when_receiving_a_result/and_the_model_has_a_calendar_collection.js +52 -0
  18. package/dist/esm/queries/for_ObservableQueryFor/when_receiving_a_result/and_the_model_has_a_calendar_collection.js.map +1 -0
  19. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +1 -1
  21. package/queries/ObservableQueryFor.ts +10 -10
  22. package/queries/for_ObservableQueryFor/given/TestQueries.ts +30 -1
  23. package/queries/for_ObservableQueryFor/given/an_observable_query_for.ts +3 -0
  24. package/queries/for_ObservableQueryFor/when_receiving_a_result/and_the_model_has_a_calendar_collection.ts +76 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/arc",
3
- "version": "22.0.1",
3
+ "version": "22.0.2",
4
4
  "description": "",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",
@@ -1,14 +1,14 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
- import { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';
4
+ import type { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';
5
5
  import { ObservableQuerySubscription } from './ObservableQuerySubscription';
6
6
  import { ValidateRequestArguments } from './ValidateRequestArguments';
7
- import { QueryValidator } from './QueryValidator';
8
- import { IObservableQueryConnection } from './IObservableQueryConnection';
7
+ import type { QueryValidator } from './QueryValidator';
8
+ import type { IObservableQueryConnection } from './IObservableQueryConnection';
9
9
  import { NullObservableQueryConnection } from './NullObservableQueryConnection';
10
10
  import { createObservableQueryConnection } from './ObservableQueryConnectionFactory';
11
- import { Constructor } from '@cratis/fundamentals';
11
+ import type { Constructor } from '@cratis/fundamentals';
12
12
  import { deserializeQueryModel, deserializeQueryModels } from './deserializeQueryModel';
13
13
  import { QueryResult } from './QueryResult';
14
14
  import { Sorting } from './Sorting';
@@ -16,10 +16,10 @@ import { Paging } from './Paging';
16
16
  import { SortDirection } from './SortDirection';
17
17
  import { Globals } from '../Globals';
18
18
  import { UrlHelpers } from '../UrlHelpers';
19
- import { GetHttpHeaders } from '../GetHttpHeaders';
20
- import { ParameterDescriptor } from '../reflection/ParameterDescriptor';
19
+ import type { GetHttpHeaders } from '../GetHttpHeaders';
20
+ import type { ParameterDescriptor } from '../reflection/ParameterDescriptor';
21
21
  import { ParametersHelper } from '../reflection/ParametersHelper';
22
- import { QueryHttpMethod } from './QueryHttpMethod';
22
+ import type { QueryHttpMethod } from './QueryHttpMethod';
23
23
  import { executeQueryHttpRequest } from './QueryHttpRequest';
24
24
 
25
25
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -106,9 +106,7 @@ export abstract class ObservableQueryFor<TDataType, TParameters = object> implem
106
106
  this._connection = new NullObservableQueryConnection(
107
107
  this.defaultValue,
108
108
  QueryResult.validationFailed(clientValidationErrors, this));
109
- } else if (!this.validateArguments(args)) {
110
- this._connection = new NullObservableQueryConnection(this.defaultValue);
111
- } else {
109
+ } else if (this.validateArguments(args)) {
112
110
  this._connection = createObservableQueryConnection({
113
111
  route: this.route,
114
112
  queryName: this.queryName ?? this.constructor.name,
@@ -117,6 +115,8 @@ export abstract class ObservableQueryFor<TDataType, TParameters = object> implem
117
115
  microservice: this._microservice,
118
116
  args: args as object,
119
117
  });
118
+ } else {
119
+ this._connection = new NullObservableQueryConnection(this.defaultValue);
120
120
  }
121
121
 
122
122
  // Descriptor-backed instance properties provide defaults; fresh args passed to subscribe()
@@ -2,7 +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 { ObservableQueryFor } from '../../ObservableQueryFor';
5
- import { Constructor } from '@cratis/fundamentals';
5
+ import { Constructor, DateOnly, field, TimeOnly } from '@cratis/fundamentals';
6
6
  import { ParameterDescriptor } from '../../../reflection/ParameterDescriptor';
7
7
 
8
8
  export class TestObservableQuery extends ObservableQueryFor<string, { id: string }> {
@@ -37,6 +37,35 @@ export class TestEnumerableQuery extends ObservableQueryFor<string[], { category
37
37
  }
38
38
  }
39
39
 
40
+ export class TestCalendarChild {
41
+ @field(DateOnly)
42
+ date!: DateOnly;
43
+
44
+ @field(TimeOnly)
45
+ time!: TimeOnly;
46
+ }
47
+
48
+ export class TestCalendarItem {
49
+ @field(TestCalendarChild, true)
50
+ children!: TestCalendarChild[];
51
+ }
52
+
53
+ export class TestCalendarEnumerableQuery extends ObservableQueryFor<TestCalendarItem[], { category: string }> {
54
+ readonly route = '/api/calendar-items/{category}';
55
+ readonly defaultValue: TestCalendarItem[] = [];
56
+ readonly parameterDescriptors: ParameterDescriptor[] = [
57
+ new ParameterDescriptor('category', String as Constructor)
58
+ ];
59
+
60
+ get requiredRequestParameters(): string[] {
61
+ return ['category'];
62
+ }
63
+
64
+ constructor() {
65
+ super(TestCalendarItem, true);
66
+ }
67
+ }
68
+
40
69
  export class TestObservableQueryWithParameterDescriptorValues extends ObservableQueryFor<string, object> {
41
70
  readonly route = '/api/search';
42
71
  readonly defaultValue = '';
@@ -4,6 +4,7 @@
4
4
  import {
5
5
  TestObservableQuery,
6
6
  TestEnumerableQuery,
7
+ TestCalendarEnumerableQuery,
7
8
  TestObservableQueryWithParameterDescriptorValues,
8
9
  TestObservableQueryWithRouteAndQueryArgs,
9
10
  TestObservableQueryWithMultipleRequiredParameters
@@ -12,6 +13,7 @@ import {
12
13
  export class an_observable_query_for {
13
14
  query: TestObservableQuery;
14
15
  enumerableQuery: TestEnumerableQuery;
16
+ calendarEnumerableQuery: TestCalendarEnumerableQuery;
15
17
  queryWithParameterDescriptorValues: TestObservableQueryWithParameterDescriptorValues;
16
18
  queryWithRouteAndQueryArgs: TestObservableQueryWithRouteAndQueryArgs;
17
19
  queryWithMultipleRequiredParameters: TestObservableQueryWithMultipleRequiredParameters;
@@ -19,6 +21,7 @@ export class an_observable_query_for {
19
21
  constructor() {
20
22
  this.query = new TestObservableQuery();
21
23
  this.enumerableQuery = new TestEnumerableQuery();
24
+ this.calendarEnumerableQuery = new TestCalendarEnumerableQuery();
22
25
  this.queryWithParameterDescriptorValues = new TestObservableQueryWithParameterDescriptorValues();
23
26
  this.queryWithRouteAndQueryArgs = new TestObservableQueryWithRouteAndQueryArgs();
24
27
  this.queryWithMultipleRequiredParameters = new TestObservableQueryWithMultipleRequiredParameters();
@@ -0,0 +1,76 @@
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 * as sinon from 'sinon';
5
+ import { DateOnly, TimeOnly } from '@cratis/fundamentals';
6
+ import { an_observable_query_for } from '../given/an_observable_query_for';
7
+ import type { TestCalendarItem } from '../given/TestQueries';
8
+ import { given } from '../../../given';
9
+ import { Globals } from '../../../Globals';
10
+ import type { EventSourceFactory } from '../../../EventSourceFactory';
11
+ import type { QueryResult } from '../../QueryResult';
12
+ import { QueryTransportMethod } from '../../QueryTransportMethod';
13
+ import type { ObservableQuerySubscription } from '../../ObservableQuerySubscription';
14
+
15
+ interface FakeEventSource {
16
+ onmessage: ((event: MessageEvent) => void) | null;
17
+ onerror: (() => void) | null;
18
+ close: sinon.SinonStub;
19
+ }
20
+
21
+ describe('and the model has a calendar collection', given(an_observable_query_for, context => {
22
+ let subscription: ObservableQuerySubscription<TestCalendarItem[]>;
23
+ let fakeEventSource: FakeEventSource;
24
+ let received: QueryResult<TestCalendarItem[]>[];
25
+ let originalQueryDirectMode: boolean;
26
+ let originalTransportMethod: QueryTransportMethod;
27
+ let originalFactory: EventSourceFactory | undefined;
28
+
29
+ beforeEach(() => {
30
+ originalQueryDirectMode = Globals.queryDirectMode;
31
+ originalTransportMethod = Globals.queryTransportMethod;
32
+ originalFactory = Globals.eventSourceFactory;
33
+
34
+ Globals.queryDirectMode = true;
35
+ Globals.queryTransportMethod = QueryTransportMethod.ServerSentEvents;
36
+
37
+ fakeEventSource = { onmessage: null, onerror: null, close: sinon.stub() };
38
+ // SAFETY: The test double implements the EventSource members exercised by the query connection.
39
+ Globals.eventSourceFactory = (() => fakeEventSource) as unknown as EventSourceFactory;
40
+
41
+ context.calendarEnumerableQuery.setOrigin('https://example.com');
42
+
43
+ received = [];
44
+ subscription = context.calendarEnumerableQuery.subscribe(
45
+ result => received.push(result),
46
+ { category: 'test-category' });
47
+
48
+ fakeEventSource.onmessage!({
49
+ data: JSON.stringify({
50
+ data: [{ children: [{ date: '2026-02-03', time: '14:15:16' }] }],
51
+ isSuccess: true,
52
+ isAuthorized: true,
53
+ isValid: true,
54
+ hasExceptions: false,
55
+ validationResults: [],
56
+ exceptionMessages: [],
57
+ exceptionStackTrace: '',
58
+ paging: { page: 0, size: 0, totalItems: 1, totalPages: 1 }
59
+ })
60
+ } as MessageEvent);
61
+ });
62
+
63
+ afterEach(() => {
64
+ subscription?.unsubscribe();
65
+ Globals.queryDirectMode = originalQueryDirectMode;
66
+ Globals.queryTransportMethod = originalTransportMethod;
67
+ Globals.eventSourceFactory = originalFactory;
68
+ sinon.restore();
69
+ });
70
+
71
+ it('should deliver the result to the subscriber', () => received.length.should.equal(1));
72
+ it('should deserialize the child date', () => received[0].data[0].children[0].date.should.be.instanceOf(DateOnly));
73
+ it('should preserve the child date', () => received[0].data[0].children[0].date.equals(DateOnly.from(2026, 2, 3)).should.be.true);
74
+ it('should deserialize the child time', () => received[0].data[0].children[0].time.should.be.instanceOf(TimeOnly));
75
+ it('should preserve the child time', () => received[0].data[0].children[0].time.equals(TimeOnly.from(14, 15, 16)).should.be.true);
76
+ }));