@cratis/arc 20.6.0 → 20.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Globals.ts +25 -0
- package/dist/cjs/Globals.d.ts +5 -0
- package/dist/cjs/Globals.d.ts.map +1 -1
- package/dist/cjs/Globals.js +6 -0
- package/dist/cjs/Globals.js.map +1 -1
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/queries/ChangeSet.d.ts +6 -0
- package/dist/cjs/queries/ChangeSet.d.ts.map +1 -0
- package/dist/cjs/queries/IChangeStreamFor.d.ts +4 -0
- package/dist/cjs/queries/IChangeStreamFor.d.ts.map +1 -0
- package/dist/cjs/queries/IQueryResult.d.ts +2 -0
- package/dist/cjs/queries/IQueryResult.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryMultiplexer.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryMultiplexer.js +1 -0
- package/dist/cjs/queries/ObservableQueryMultiplexer.js.map +1 -1
- package/dist/cjs/queries/QueryResult.d.ts +8 -0
- package/dist/cjs/queries/QueryResult.d.ts.map +1 -1
- package/dist/cjs/queries/QueryResult.js +8 -0
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/queries/QueryResultWithState.d.ts +3 -1
- package/dist/cjs/queries/QueryResultWithState.d.ts.map +1 -1
- package/dist/cjs/queries/QueryResultWithState.js +4 -2
- package/dist/cjs/queries/QueryResultWithState.js.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.d.ts +1 -0
- package/dist/cjs/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/cjs/queries/index.d.ts +2 -0
- package/dist/cjs/queries/index.d.ts.map +1 -1
- package/dist/esm/Globals.d.ts +5 -0
- package/dist/esm/Globals.d.ts.map +1 -1
- package/dist/esm/Globals.js +7 -1
- package/dist/esm/Globals.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/queries/ChangeSet.d.ts +6 -0
- package/dist/esm/queries/ChangeSet.d.ts.map +1 -0
- package/dist/esm/queries/ChangeSet.js +2 -0
- package/dist/esm/queries/ChangeSet.js.map +1 -0
- package/dist/esm/queries/IChangeStreamFor.d.ts +4 -0
- package/dist/esm/queries/IChangeStreamFor.d.ts.map +1 -0
- package/dist/esm/queries/IChangeStreamFor.js +2 -0
- package/dist/esm/queries/IChangeStreamFor.js.map +1 -0
- package/dist/esm/queries/IQueryResult.d.ts +2 -0
- package/dist/esm/queries/IQueryResult.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryMultiplexer.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryMultiplexer.js +1 -0
- package/dist/esm/queries/ObservableQueryMultiplexer.js.map +1 -1
- package/dist/esm/queries/QueryResult.d.ts +8 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +8 -0
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/QueryResultWithState.d.ts +3 -1
- package/dist/esm/queries/QueryResultWithState.d.ts.map +1 -1
- package/dist/esm/queries/QueryResultWithState.js +4 -2
- package/dist/esm/queries/QueryResultWithState.js.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.d.ts +1 -0
- package/dist/esm/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/esm/queries/index.d.ts +2 -0
- package/dist/esm/queries/index.d.ts.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/ChangeSet.ts +24 -0
- package/queries/IChangeStreamFor.ts +14 -0
- package/queries/IQueryResult.ts +8 -0
- package/queries/ObservableQueryMultiplexer.ts +3 -0
- package/queries/QueryResult.ts +27 -0
- package/queries/QueryResultWithState.ts +6 -2
- package/queries/WebSocketHubConnection.ts +1 -0
- package/queries/index.ts +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Represents the set of changes in an observable query result, describing
|
|
6
|
+
* which items were added, replaced, or removed since the previous update.
|
|
7
|
+
* @template T The item type in the observable collection.
|
|
8
|
+
*/
|
|
9
|
+
export interface ChangeSet<T> {
|
|
10
|
+
/**
|
|
11
|
+
* Items that were added since the last update.
|
|
12
|
+
*/
|
|
13
|
+
readonly added: T[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Items that were replaced (same identity, updated content) since the last update.
|
|
17
|
+
*/
|
|
18
|
+
readonly replaced: T[];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Items that were removed since the last update.
|
|
22
|
+
*/
|
|
23
|
+
readonly removed: T[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { IObservableQueryFor } from './IObservableQueryFor';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines a change-stream-capable observable query. Any {@link IObservableQueryFor} returning
|
|
8
|
+
* an enumerable ({@code TDataType[]}) satisfies this interface automatically, enabling it to
|
|
9
|
+
* be used with the {@code useChangeStream} React hook which delivers per-update deltas
|
|
10
|
+
* (added / replaced / removed) instead of the full collection.
|
|
11
|
+
* @template TDataType The element type of the observable collection (not the array itself).
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
14
|
+
export interface IChangeStreamFor<TDataType> extends IObservableQueryFor<TDataType[]> {}
|
package/queries/IQueryResult.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { ValidationResult } from '../validation/ValidationResult';
|
|
5
5
|
import { PagingInfo } from './PagingInfo';
|
|
6
|
+
import { ChangeSet } from './ChangeSet';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Defines the result from executing a query.
|
|
@@ -53,6 +54,13 @@ export interface IQueryResult<TDataType> {
|
|
|
53
54
|
*/
|
|
54
55
|
readonly exceptionStackTrace: string;
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Gets the optional change set describing what changed since the previous update.
|
|
59
|
+
* When present (server-side delta mode), clients apply the delta to local state instead
|
|
60
|
+
* of replacing the full dataset.
|
|
61
|
+
*/
|
|
62
|
+
readonly changeSet?: ChangeSet<unknown>;
|
|
63
|
+
|
|
56
64
|
/**
|
|
57
65
|
* Gets whether or not the query has data.
|
|
58
66
|
*/
|
|
@@ -107,6 +107,9 @@ export class ObservableQueryMultiplexer {
|
|
|
107
107
|
private buildSubscriptionRequest(queryName: string, args?: object): SubscriptionRequest {
|
|
108
108
|
const request: SubscriptionRequest = { queryName };
|
|
109
109
|
|
|
110
|
+
// Always include the transfer mode so the server knows which emission strategy to use.
|
|
111
|
+
request.transferMode = Globals.observableQueryTransferMode;
|
|
112
|
+
|
|
110
113
|
if (!args) return request;
|
|
111
114
|
|
|
112
115
|
const a = args as Record<string, any>;
|
package/queries/QueryResult.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Constructor, JsonSerializer } from '@cratis/fundamentals';
|
|
|
5
5
|
import { ValidationResult } from '../validation/ValidationResult';
|
|
6
6
|
import { IQueryResult } from './IQueryResult';
|
|
7
7
|
import { PagingInfo } from './PagingInfo';
|
|
8
|
+
import { ChangeSet } from './ChangeSet';
|
|
8
9
|
|
|
9
10
|
type ServerQueryResult = {
|
|
10
11
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -18,6 +19,16 @@ type ServerQueryResult = {
|
|
|
18
19
|
exceptionMessages: string[];
|
|
19
20
|
exceptionStackTrace: string;
|
|
20
21
|
paging: ServerPagingInfo;
|
|
22
|
+
changeSet?: ServerChangeSet;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ServerChangeSet = {
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
added: any[];
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
replaced: any[];
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
removed: any[];
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
type ServerValidationResult = {
|
|
@@ -132,6 +143,14 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
|
|
|
132
143
|
} else {
|
|
133
144
|
this.data = (enumerable ? [] : null) as TDataType;
|
|
134
145
|
}
|
|
146
|
+
|
|
147
|
+
if (enumerable && result.changeSet) {
|
|
148
|
+
this.changeSet = {
|
|
149
|
+
added: JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.added ?? []),
|
|
150
|
+
replaced: JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.replaced ?? []),
|
|
151
|
+
removed: JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.removed ?? []),
|
|
152
|
+
} as ChangeSet<unknown>;
|
|
153
|
+
}
|
|
135
154
|
}
|
|
136
155
|
|
|
137
156
|
/** @inheritdoc */
|
|
@@ -161,6 +180,14 @@ export class QueryResult<TDataType = object> implements IQueryResult<TDataType>
|
|
|
161
180
|
/** @inheritdoc */
|
|
162
181
|
readonly exceptionStackTrace: string;
|
|
163
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Gets the optional change set describing what changed since the previous update.
|
|
185
|
+
* Set by the server when the delta transfer mode is active.
|
|
186
|
+
* When present, clients can apply the delta to their local state rather than replacing
|
|
187
|
+
* the full dataset.
|
|
188
|
+
*/
|
|
189
|
+
readonly changeSet?: ChangeSet<unknown>;
|
|
190
|
+
|
|
164
191
|
/**
|
|
165
192
|
* Gets whether or not the query has data.
|
|
166
193
|
*/
|
|
@@ -5,6 +5,7 @@ import { ValidationResult } from '../validation/ValidationResult';
|
|
|
5
5
|
import { IQueryResult } from './IQueryResult';
|
|
6
6
|
import { PagingInfo } from './PagingInfo';
|
|
7
7
|
import { QueryResult } from './QueryResult';
|
|
8
|
+
import { ChangeSet } from './ChangeSet';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Represents a specialized {@link QueryResult<TDataType>} that holds state for its execution
|
|
@@ -51,6 +52,7 @@ export class QueryResultWithState<TDataType> implements IQueryResult<TDataType>
|
|
|
51
52
|
* @param {string[]} exceptionMessages Any exception messages.
|
|
52
53
|
* @param {string} exceptionStackTrace Exception stack trace, if any.
|
|
53
54
|
* @param {boolean} isPerforming Whether or not the query is being performed. True if its performing, false if it is done.
|
|
55
|
+
* @param {ChangeSet<unknown> | undefined} changeSet Optional change set from the server describing the delta since the last update.
|
|
54
56
|
*/
|
|
55
57
|
constructor(
|
|
56
58
|
readonly data: TDataType,
|
|
@@ -62,7 +64,8 @@ export class QueryResultWithState<TDataType> implements IQueryResult<TDataType>
|
|
|
62
64
|
readonly hasExceptions: boolean,
|
|
63
65
|
readonly exceptionMessages: string[],
|
|
64
66
|
readonly exceptionStackTrace: string,
|
|
65
|
-
readonly isPerforming: boolean
|
|
67
|
+
readonly isPerforming: boolean,
|
|
68
|
+
readonly changeSet?: ChangeSet<unknown>) {
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
/** @inheritdoc */
|
|
@@ -90,6 +93,7 @@ export class QueryResultWithState<TDataType> implements IQueryResult<TDataType>
|
|
|
90
93
|
queryResult.hasExceptions,
|
|
91
94
|
queryResult.exceptionMessages,
|
|
92
95
|
queryResult.exceptionStackTrace,
|
|
93
|
-
isPerforming
|
|
96
|
+
isPerforming,
|
|
97
|
+
queryResult.changeSet);
|
|
94
98
|
}
|
|
95
99
|
}
|
package/queries/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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
|
+
export * from './ChangeSet';
|
|
5
|
+
export * from './IChangeStreamFor';
|
|
4
6
|
export * from './IQuery';
|
|
5
7
|
export * from './IQueryFor';
|
|
6
8
|
export * from './Paging';
|