@cratis/arc 20.59.1 → 20.60.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/dist/cjs/queries/NullObservableQueryConnection.js +7 -2
- package/dist/cjs/queries/NullObservableQueryConnection.js.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.js +11 -1
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
- package/dist/cjs/queries/QueryFor.js +1 -21
- package/dist/cjs/queries/QueryFor.js.map +1 -1
- package/dist/cjs/queries/QueryResult.js +30 -0
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/NullObservableQueryConnection.d.ts +3 -1
- package/dist/esm/queries/NullObservableQueryConnection.d.ts.map +1 -1
- package/dist/esm/queries/NullObservableQueryConnection.js +7 -2
- package/dist/esm/queries/NullObservableQueryConnection.js.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.d.ts +2 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.js +11 -1
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
- package/dist/esm/queries/QueryFor.d.ts.map +1 -1
- package/dist/esm/queries/QueryFor.js +1 -21
- package/dist/esm/queries/QueryFor.js.map +1 -1
- package/dist/esm/queries/QueryResult.d.ts +5 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +30 -0
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_with_validator.d.ts +23 -0
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_with_validator.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_with_validator.js +28 -0
- package/dist/esm/queries/for_ObservableQueryFor/given/an_observable_query_with_validator.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_client_validation_failing.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_client_validation_failing.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_client_validation_failing.js +21 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_client_validation_failing.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_failing.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_failing.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_failing.js +18 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_failing.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_passing.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_passing.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_passing.js +21 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_passing.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/NullObservableQueryConnection.ts +5 -2
- package/queries/ObservableQueryFor.ts +15 -1
- package/queries/QueryFor.ts +1 -21
- package/queries/QueryResult.ts +34 -0
- package/queries/for_ObservableQueryFor/given/an_observable_query_with_validator.ts +41 -0
- package/queries/for_ObservableQueryFor/when_performing/with_client_validation_failing.ts +30 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_failing.ts +26 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_client_validation_passing.ts +32 -0
|
@@ -8,11 +8,16 @@ var QueryResult = require('./QueryResult.js');
|
|
|
8
8
|
* Represents a {@link IObservableQueryConnection} when for instance one can't establish a connection.
|
|
9
9
|
*/ class NullObservableQueryConnection {
|
|
10
10
|
defaultValue;
|
|
11
|
+
result;
|
|
11
12
|
/**
|
|
12
13
|
* Initializes a new instance of the {@link NullObservableQueryConnection} class.
|
|
13
14
|
* @param {TDataType} defaultValue The default value to serve.
|
|
14
|
-
|
|
15
|
+
* @param {QueryResult<TDataType>} result Optional result to serve instead of an empty one. Supply it when the
|
|
16
|
+
* subscription failed for a reason the subscriber must be able to see — client-side validation in particular,
|
|
17
|
+
* which would otherwise be indistinguishable from a query that simply has no data yet.
|
|
18
|
+
*/ constructor(defaultValue, result){
|
|
15
19
|
this.defaultValue = defaultValue;
|
|
20
|
+
this.result = result;
|
|
16
21
|
}
|
|
17
22
|
/** @inheritdoc */ get lastPingLatency() {
|
|
18
23
|
return 0;
|
|
@@ -21,7 +26,7 @@ var QueryResult = require('./QueryResult.js');
|
|
|
21
26
|
return 0;
|
|
22
27
|
}
|
|
23
28
|
/** @inheritdoc */ connect(dataReceived) {
|
|
24
|
-
dataReceived(QueryResult.QueryResult.empty(this.defaultValue));
|
|
29
|
+
dataReceived(this.result ?? QueryResult.QueryResult.empty(this.defaultValue));
|
|
25
30
|
}
|
|
26
31
|
/** @inheritdoc */ /* eslint-disable @typescript-eslint/no-empty-function */ disconnect() {}
|
|
27
32
|
}
|
|
@@ -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 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":["NullObservableQueryConnection","defaultValue","lastPingLatency","averageLatency","connect","dataReceived","QueryResult","empty","disconnect"],"mappings":";;;;AAAA;AACA;AAMA;;AAEC,IAEM,MAAMA,6BAAAA,CAAAA
|
|
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 * @param {QueryResult<TDataType>} result Optional result to serve instead of an empty one. Supply it when the\n * subscription failed for a reason the subscriber must be able to see — client-side validation in particular,\n * which would otherwise be indistinguishable from a query that simply has no data yet.\n */\n constructor(readonly defaultValue: TDataType, readonly result?: QueryResult<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(this.result ?? QueryResult.empty(this.defaultValue));\n }\n\n /** @inheritdoc */\n /* eslint-disable @typescript-eslint/no-empty-function */\n disconnect() {\n }\n}\n"],"names":["NullObservableQueryConnection","result","defaultValue","lastPingLatency","averageLatency","connect","dataReceived","QueryResult","empty","disconnect"],"mappings":";;;;AAAA;AACA;AAMA;;AAEC,IAEM,MAAMA,6BAAAA,CAAAA;;;AACT;;;;;;AAMC,QACD,YAAY,YAAgC,EAAWC,MAA+B,CAAE;aAAnEC,YAAAA,GAAAA,YAAAA;aAAkCD,MAAAA,GAAAA,MAAAA;AACvD,IAAA;uBAGA,IAAIE,eAAAA,GAA0B;QAC1B,OAAO,CAAA;AACX,IAAA;uBAGA,IAAIC,cAAAA,GAAyB;QACzB,OAAO,CAAA;AACX,IAAA;uBAGAC,OAAAA,CAAQC,YAAqC,EAAE;QAC3CA,YAAAA,CAAa,IAAI,CAACL,MAAM,IAAIM,wBAAYC,KAAK,CAAC,IAAI,CAACN,YAAY,CAAA,CAAA;AACnE,IAAA;AAEA,iFAEAO,UAAAA,GAAa,CACb;AACJ;;;;"}
|
|
@@ -29,6 +29,7 @@ var QueryHttpRequest = require('./QueryHttpRequest.js');
|
|
|
29
29
|
_httpHeadersCallback;
|
|
30
30
|
_httpMethod;
|
|
31
31
|
roles = [];
|
|
32
|
+
validation;
|
|
32
33
|
/** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */ queryName;
|
|
33
34
|
sorting;
|
|
34
35
|
paging;
|
|
@@ -70,7 +71,12 @@ var QueryHttpRequest = require('./QueryHttpRequest.js');
|
|
|
70
71
|
if (this._connection) {
|
|
71
72
|
this._connection.disconnect();
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
+
const clientValidationErrors = this.validation?.validate(args || {}) || [];
|
|
75
|
+
if (clientValidationErrors.length > 0) {
|
|
76
|
+
// Serve the failure through the connection rather than throwing, so a subscriber sees an invalid result
|
|
77
|
+
// on its normal callback path instead of the empty result an unestablished connection would emit.
|
|
78
|
+
this._connection = new NullObservableQueryConnection.NullObservableQueryConnection(this.defaultValue, QueryResult.QueryResult.validationFailed(clientValidationErrors, this));
|
|
79
|
+
} else if (!this.validateArguments(args)) {
|
|
74
80
|
this._connection = new NullObservableQueryConnection.NullObservableQueryConnection(this.defaultValue);
|
|
75
81
|
} else {
|
|
76
82
|
this._connection = ObservableQueryConnectionFactory.createObservableQueryConnection({
|
|
@@ -116,6 +122,10 @@ var QueryHttpRequest = require('./QueryHttpRequest.js');
|
|
|
116
122
|
data: this.defaultValue
|
|
117
123
|
}
|
|
118
124
|
};
|
|
125
|
+
const clientValidationErrors = this.validation?.validate(args || {}) || [];
|
|
126
|
+
if (clientValidationErrors.length > 0) {
|
|
127
|
+
return QueryResult.QueryResult.validationFailed(clientValidationErrors, this);
|
|
128
|
+
}
|
|
119
129
|
if (!this.validateArguments(args)) {
|
|
120
130
|
return new Promise((resolve)=>{
|
|
121
131
|
resolve(noSuccess);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { createObservableQueryConnection } from './ObservableQueryConnectionFactory';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\nimport { QueryHttpMethod } from './QueryHttpMethod';\nimport { executeQueryHttpRequest } from './QueryHttpRequest';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n private _httpMethod?: QueryHttpMethod;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n readonly roles: string[] = [];\n /** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */\n readonly queryName?: string;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n setHttpMethod(method: QueryHttpMethod): void {\n this._httpMethod = method;\n }\n\n /** @inheritdoc */\n subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n this._connection = createObservableQueryConnection({\n route: this.route,\n queryName: this.queryName ?? this.constructor.name,\n origin: this._origin,\n apiBasePath: this._apiBasePath,\n microservice: this._microservice,\n args: args as object,\n });\n }\n\n // Descriptor-backed instance properties provide defaults; fresh args passed to subscribe()\n // must take precedence over any stale instance property values. Spread parameterValues\n // first so that the caller-supplied args can override them.\n //\n // In direct mode the route arguments are already embedded in the URL path, so only\n // the unused (non-route) parameters are appended as additional query arguments.\n // In multiplexed mode ALL arguments — including route-derived ones — must be included\n // in the subscribe payload so the server can execute the query correctly.\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...parameterValues,\n ...(Globals.queryDirectMode ? unusedParameters : (args as object) || {}),\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await executeQueryHttpRequest(this._httpMethod, {\n route: this.route,\n apiBasePath: this._apiBasePath,\n origin: this._origin,\n args: (args as object) ?? {},\n parameterValues,\n paging: this.paging,\n sorting: this.sorting,\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else if (result.data) {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["ObservableQueryFor","_microservice","_apiBasePath","_origin","_connection","_httpHeadersCallback","_httpMethod","roles","queryName","sorting","paging","enumerable","modelType","Sorting","none","Paging","noPaging","Globals","microservice","apiBasePath","origin","dispose","disconnect","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","setHttpMethod","method","subscribe","args","validateArguments","NullObservableQueryConnection","defaultValue","createObservableQueryConnection","route","name","parameterValues","ParametersHelper","collectParameterValues","unusedParameters","UrlHelpers","replaceRouteParameters","connectionQueryArguments","queryDirectMode","buildQueryArguments","subscriber","ObservableQuerySubscription","connect","data","result","deserializeResult","ex","console","log","perform","noSuccess","QueryResult","Promise","resolve","headers","length","microserviceHttpHeader","response","executeQueryHttpRequest","json","combinedArgs","ValidateRequestArguments","requiredRequestParameters","queryArguments","pageSize","page","hasSorting","sortBy","field","sortDirection","direction","SortDirection","descending","Array","isArray","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AAsBA;;;AAKC,IACM,MAAeA,kB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CAACkE,KAAK;AAC1CL,YAAAA,cAAAA,CAAeM,aAAa,GAAG,IAAK,CAACnE,OAAO,CAACoE,SAAS,KAAKC,2BAAAA,CAAcC,UAAU,GAAI,MAAA,GAAS,KAAA;AACpG,QAAA;QAEA,OAAOT,cAAAA;AACX,IAAA;AAEQlB,IAAAA,iBAAAA,CAAkBD,MAAW,EAAQ;QACzC,IAAI,IAAI,CAACxC,UAAU,EAAE;AACjB,YAAA,IAAIqE,KAAAA,CAAMC,OAAO,CAAC9B,MAAAA,CAAOD,IAAI,CAAA,EAAG;gBAC5BC,MAAAA,CAAOD,IAAI,GAAGgC,2BAAAA,CAAeC,4BAA4B,CAAC,IAAI,CAACvE,SAAS,EAAEuC,MAAAA,CAAOD,IAAI,CAAA;YACzF,CAAA,MAAO;gBACHC,MAAAA,CAAOD,IAAI,GAAG,EAAE;AACpB,YAAA;QACJ,CAAA,MAAO,IAAIC,MAAAA,CAAOD,IAAI,EAAE;YACpBC,MAAAA,CAAOD,IAAI,GAAGgC,2BAAAA,CAAeE,uBAAuB,CAAC,IAAI,CAACxE,SAAS,EAAEuC,MAAAA,CAAOD,IAAI,CAAA;AACpF,QAAA;AACJ,IAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { QueryValidator } from './QueryValidator';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { createObservableQueryConnection } from './ObservableQueryConnectionFactory';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\nimport { QueryHttpMethod } from './QueryHttpMethod';\nimport { executeQueryHttpRequest } from './QueryHttpRequest';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n private _httpMethod?: QueryHttpMethod;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n readonly roles: string[] = [];\n readonly validation?: QueryValidator<any>;\n /** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */\n readonly queryName?: string;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n setHttpMethod(method: QueryHttpMethod): void {\n this._httpMethod = method;\n }\n\n /** @inheritdoc */\n subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n // Serve the failure through the connection rather than throwing, so a subscriber sees an invalid result\n // on its normal callback path instead of the empty result an unestablished connection would emit.\n this._connection = new NullObservableQueryConnection(\n this.defaultValue,\n QueryResult.validationFailed(clientValidationErrors, this));\n } else if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n this._connection = createObservableQueryConnection({\n route: this.route,\n queryName: this.queryName ?? this.constructor.name,\n origin: this._origin,\n apiBasePath: this._apiBasePath,\n microservice: this._microservice,\n args: args as object,\n });\n }\n\n // Descriptor-backed instance properties provide defaults; fresh args passed to subscribe()\n // must take precedence over any stale instance property values. Spread parameterValues\n // first so that the caller-supplied args can override them.\n //\n // In direct mode the route arguments are already embedded in the URL path, so only\n // the unused (non-route) parameters are appended as additional query arguments.\n // In multiplexed mode ALL arguments — including route-derived ones — must be included\n // in the subscribe payload so the server can execute the query correctly.\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...parameterValues,\n ...(Globals.queryDirectMode ? unusedParameters : (args as object) || {}),\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n return QueryResult.validationFailed(clientValidationErrors, this);\n }\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await executeQueryHttpRequest(this._httpMethod, {\n route: this.route,\n apiBasePath: this._apiBasePath,\n origin: this._origin,\n args: (args as object) ?? {},\n parameterValues,\n paging: this.paging,\n sorting: this.sorting,\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else if (result.data) {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["ObservableQueryFor","_microservice","_apiBasePath","_origin","_connection","_httpHeadersCallback","_httpMethod","roles","validation","queryName","sorting","paging","enumerable","modelType","Sorting","none","Paging","noPaging","Globals","microservice","apiBasePath","origin","dispose","disconnect","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","setHttpMethod","method","subscribe","args","clientValidationErrors","validate","length","NullObservableQueryConnection","defaultValue","QueryResult","validationFailed","validateArguments","createObservableQueryConnection","route","name","parameterValues","ParametersHelper","collectParameterValues","unusedParameters","UrlHelpers","replaceRouteParameters","connectionQueryArguments","queryDirectMode","buildQueryArguments","subscriber","ObservableQuerySubscription","connect","data","result","deserializeResult","ex","console","log","perform","noSuccess","Promise","resolve","headers","microserviceHttpHeader","response","executeQueryHttpRequest","json","combinedArgs","ValidateRequestArguments","requiredRequestParameters","queryArguments","pageSize","page","hasSorting","sortBy","field","sortDirection","direction","SortDirection","descending","Array","isArray","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AAuBA;;;AAKC,IACM,MAAeA,kBAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,WAAAA;IACAC,oBAAAA;IACAC,WAAAA;AAICC,IAAAA,KAAAA,GAAkB,EAAE;IACpBC,UAAAA;sHAET,SAASC;IAGTC,OAAAA;IACAC,MAAAA;AAEA;;;;AAIC,QACD,YAAY,SAA+B,EAAWC,UAAmB,CAAE;aAAtDC,SAAAA,GAAAA,SAAAA;aAAiCD,UAAAA,GAAAA,UAAAA;AAClD,QAAA,IAAI,CAACF,OAAO,GAAGI,eAAAA,CAAQC,IAAI;AAC3B,QAAA,IAAI,CAACJ,MAAM,GAAGK,aAAAA,CAAOC,QAAQ;AAC7B,QAAA,IAAI,CAAChB,aAAa,GAAGiB,eAAAA,CAAQC,YAAY,IAAI,EAAA;A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,CAAClE,OAAO,CAACmE,UAAU,EAAE;AACzBH,YAAAA,cAAAA,CAAeI,MAAM,GAAG,IAAI,CAACpE,OAAO,CAACqE,KAAK;AAC1CL,YAAAA,cAAAA,CAAeM,aAAa,GAAG,IAAK,CAACtE,OAAO,CAACuE,SAAS,KAAKC,2BAAAA,CAAcC,UAAU,GAAI,MAAA,GAAS,KAAA;AACpG,QAAA;QAEA,OAAOT,cAAAA;AACX,IAAA;AAEQhB,IAAAA,iBAAAA,CAAkBD,MAAW,EAAQ;QACzC,IAAI,IAAI,CAAC7C,UAAU,EAAE;AACjB,YAAA,IAAIwE,KAAAA,CAAMC,OAAO,CAAC5B,MAAAA,CAAOD,IAAI,CAAA,EAAG;gBAC5BC,MAAAA,CAAOD,IAAI,GAAG8B,2BAAAA,CAAeC,4BAA4B,CAAC,IAAI,CAAC1E,SAAS,EAAE4C,MAAAA,CAAOD,IAAI,CAAA;YACzF,CAAA,MAAO;gBACHC,MAAAA,CAAOD,IAAI,GAAG,EAAE;AACpB,YAAA;QACJ,CAAA,MAAO,IAAIC,MAAAA,CAAOD,IAAI,EAAE;YACpBC,MAAAA,CAAOD,IAAI,GAAG8B,2BAAAA,CAAeE,uBAAuB,CAAC,IAAI,CAAC3E,SAAS,EAAE4C,MAAAA,CAAOD,IAAI,CAAA;AACpF,QAAA;AACJ,IAAA;AACJ;;;;"}
|
|
@@ -67,27 +67,7 @@ var QueryHttpRequest = require('./QueryHttpRequest.js');
|
|
|
67
67
|
args = args || this.parameters;
|
|
68
68
|
const clientValidationErrors = this.validation?.validate(args || {}) || [];
|
|
69
69
|
if (clientValidationErrors.length > 0) {
|
|
70
|
-
return
|
|
71
|
-
data: this.defaultValue,
|
|
72
|
-
isSuccess: false,
|
|
73
|
-
isAuthorized: true,
|
|
74
|
-
isValid: false,
|
|
75
|
-
hasExceptions: false,
|
|
76
|
-
validationResults: clientValidationErrors.map((_)=>({
|
|
77
|
-
severity: _.severity,
|
|
78
|
-
message: _.message,
|
|
79
|
-
members: _.members,
|
|
80
|
-
state: _.state
|
|
81
|
-
})),
|
|
82
|
-
exceptionMessages: [],
|
|
83
|
-
exceptionStackTrace: '',
|
|
84
|
-
paging: {
|
|
85
|
-
totalItems: 0,
|
|
86
|
-
totalPages: 0,
|
|
87
|
-
page: 0,
|
|
88
|
-
size: 0
|
|
89
|
-
}
|
|
90
|
-
}, this.modelType, this.enumerable);
|
|
70
|
+
return QueryResult.QueryResult.validationFailed(clientValidationErrors, this);
|
|
91
71
|
}
|
|
92
72
|
if (!ValidateRequestArguments.ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args)) {
|
|
93
73
|
return new Promise((resolve)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryFor.js","sources":["../../../queries/QueryFor.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 { IQueryFor } from './IQueryFor';\nimport { QueryResult } from \"./QueryResult\";\nimport { QueryValidator } from './QueryValidator';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { Constructor } from '@cratis/fundamentals';\nimport { Paging } from './Paging';\nimport { Globals } from '../Globals';\nimport { Sorting } from './Sorting';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\nimport { QueryHttpMethod } from './QueryHttpMethod';\nimport { executeQueryHttpRequest } from './QueryHttpRequest';\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class QueryFor<TDataType, TParameters = object> implements IQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n private _httpMethod?: QueryHttpMethod;\n abstract readonly route: string;\n /** Backend fully-qualified query name used as cache key. Overridden in generated proxies. */\n readonly queryName?: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: QueryValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n abstract defaultValue: TDataType;\n abortController?: AbortController;\n sorting: Sorting;\n paging: Paging;\n parameters: TParameters | undefined;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n setHttpMethod(method: QueryHttpMethod): void {\n this._httpMethod = method;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n args = args || this.parameters;\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n return new QueryResult({\n data: this.defaultValue as object,\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: clientValidationErrors.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, this.modelType, this.enumerable) as QueryResult<TDataType>;\n }\n\n if (!ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n if (this.abortController) {\n this.abortController.abort();\n }\n\n this.abortController = new AbortController();\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const headers = {\n ... this._httpHeadersCallback?.(), ...\n {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await executeQueryHttpRequest(this._httpMethod, {\n route: this.route,\n apiBasePath: this._apiBasePath,\n origin: this._origin,\n args: (args as object) ?? {},\n parameterValues,\n paging: this.paging,\n sorting: this.sorting,\n headers,\n signal: this.abortController.signal\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n}\n"],"names":["QueryFor","_microservice","_apiBasePath","_origin","_httpHeadersCallback","_httpMethod","queryName","validation","roles","abortController","sorting","paging","parameters","enumerable","modelType","Sorting","none","Paging","noPaging","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","setHttpMethod","method","perform","args","noSuccess","QueryResult","data","defaultValue","clientValidationErrors","validate","length","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","map","_","severity","message","members","state","exceptionMessages","exceptionStackTrace","totalItems","totalPages","page","size","ValidateRequestArguments","name","requiredRequestParameters","Promise","resolve","abort","AbortController","parameterValues","ParametersHelper","collectParameterValues","headers","microserviceHttpHeader","response","executeQueryHttpRequest","route","signal","result","json"],"mappings":";;;;;;;;;;AAAA;AACA;AAgBA;;;AAGC,IACM,MAAeA,QAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;IACAC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
|
1
|
+
{"version":3,"file":"QueryFor.js","sources":["../../../queries/QueryFor.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 { IQueryFor } from './IQueryFor';\nimport { QueryResult } from \"./QueryResult\";\nimport { QueryValidator } from './QueryValidator';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { Constructor } from '@cratis/fundamentals';\nimport { Paging } from './Paging';\nimport { Globals } from '../Globals';\nimport { Sorting } from './Sorting';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\nimport { QueryHttpMethod } from './QueryHttpMethod';\nimport { executeQueryHttpRequest } from './QueryHttpRequest';\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class QueryFor<TDataType, TParameters = object> implements IQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n private _httpMethod?: QueryHttpMethod;\n abstract readonly route: string;\n /** Backend fully-qualified query name used as cache key. Overridden in generated proxies. */\n readonly queryName?: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: QueryValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n readonly roles: string[] = [];\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n abstract defaultValue: TDataType;\n abortController?: AbortController;\n sorting: Sorting;\n paging: Paging;\n parameters: TParameters | undefined;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n setHttpMethod(method: QueryHttpMethod): void {\n this._httpMethod = method;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n args = args || this.parameters;\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n return QueryResult.validationFailed(clientValidationErrors, this);\n }\n\n if (!ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n if (this.abortController) {\n this.abortController.abort();\n }\n\n this.abortController = new AbortController();\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const headers = {\n ... this._httpHeadersCallback?.(), ...\n {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await executeQueryHttpRequest(this._httpMethod, {\n route: this.route,\n apiBasePath: this._apiBasePath,\n origin: this._origin,\n args: (args as object) ?? {},\n parameterValues,\n paging: this.paging,\n sorting: this.sorting,\n headers,\n signal: this.abortController.signal\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n}\n"],"names":["QueryFor","_microservice","_apiBasePath","_origin","_httpHeadersCallback","_httpMethod","queryName","validation","roles","abortController","sorting","paging","parameters","enumerable","modelType","Sorting","none","Paging","noPaging","Globals","microservice","apiBasePath","origin","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","setHttpMethod","method","perform","args","noSuccess","QueryResult","data","defaultValue","clientValidationErrors","validate","length","validationFailed","ValidateRequestArguments","name","requiredRequestParameters","Promise","resolve","abort","AbortController","parameterValues","ParametersHelper","collectParameterValues","headers","microserviceHttpHeader","response","executeQueryHttpRequest","route","signal","result","json"],"mappings":";;;;;;;;;;AAAA;AACA;AAgBA;;;AAGC,IACM,MAAeA,QAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,oBAAAA;IACAC,WAAAA;kGAGR,SAASC;4DAET,UAASC;AACT,2DACSC,KAAAA,GAAkB,EAAE;IAI7BC,eAAAA;IACAC,OAAAA;IACAC,MAAAA;IACAC,UAAAA;AAEA;;;;AAIC,QACD,YAAY,SAA+B,EAAWC,UAAmB,CAAE;aAAtDC,SAAAA,GAAAA,SAAAA;aAAiCD,UAAAA,GAAAA,UAAAA;AAClD,QAAA,IAAI,CAACH,OAAO,GAAGK,eAAAA,CAAQC,IAAI;AAC3B,QAAA,IAAI,CAACL,MAAM,GAAGM,aAAAA,CAAOC,QAAQ;AAC7B,QAAA,IAAI,CAACjB,aAAa,GAAGkB,eAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,CAAClB,YAAY,GAAGiB,eAAAA,CAAQE,WAAW,IAAI,EAAA;AAC3C,QAAA,IAAI,CAAClB,OAAO,GAAGgB,eAAAA,CAAQG,MAAM,IAAI,EAAA;AACjC,QAAA,IAAI,CAAClB,oBAAoB,GAAG,KAAO,EAAC,CAAA;AACxC,IAAA;uBAGAmB,eAAAA,CAAgBH,YAAoB,EAAE;QAClC,IAAI,CAACnB,aAAa,GAAGmB,YAAAA;AACzB,IAAA;uBAGAI,cAAAA,CA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AG3B,QAAA,MAAMC,eAAAA,GAAkBC,iCAAAA,CAAiBC,sBAAsB,CAAC,IAAI,CAAA;AAEpE,QAAA,MAAMC,OAAAA,GAAU;YACZ,GAAI,IAAI,CAAC9C,oBAAoB,IAAI;YAAE,GACnC;gBACI,QAAA,EAAU,kBAAA;gBACV,cAAA,EAAgB;;AAExB,SAAA;AAEA,QAAA,IAAI,IAAI,CAACH,aAAa,EAAEqC,SAAS,CAAA,EAAG;AAChCY,YAAAA,OAAO,CAAC/B,eAAAA,CAAQgC,sBAAsB,CAAC,GAAG,IAAI,CAAClD,aAAa;AAChE,QAAA;AAEA,QAAA,MAAMmD,WAAW,MAAMC,wCAAAA,CAAwB,IAAI,CAAChD,WAAW,EAAE;YAC7DiD,KAAAA,EAAO,IAAI,CAACA,KAAK;YACjBjC,WAAAA,EAAa,IAAI,CAACnB,YAAY;YAC9BoB,MAAAA,EAAQ,IAAI,CAACnB,OAAO;YACpB4B,IAAAA,EAAOA,QAAmB,EAAC;AAC3BgB,YAAAA,eAAAA;YACApC,MAAAA,EAAQ,IAAI,CAACA,MAAM;YACnBD,OAAAA,EAAS,IAAI,CAACA,OAAO;AACrBwC,YAAAA,OAAAA;AACAK,YAAAA,MAAAA,EAAQ,IAAI,CAAC9C,eAAe,CAAC8C;AACjC,SAAA,CAAA;QAEA,IAAI;YACA,MAAMC,MAAAA,GAAS,MAAMJ,QAAAA,CAASK,IAAI,EAAA;YAClC,OAAO,IAAIxB,wBAAYuB,MAAAA,EAAQ,IAAI,CAAC1C,SAAS,EAAE,IAAI,CAACD,UAAU,CAAA;AAClE,QAAA,CAAA,CAAE,OAAM;YACJ,OAAOmB,SAAAA;AACX,QAAA;AACJ,IAAA;AACJ;;;;"}
|
|
@@ -28,6 +28,36 @@ var PagingInfo = require('./PagingInfo.js');
|
|
|
28
28
|
}
|
|
29
29
|
}, Object, false);
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a {@link QueryResult} representing a query rejected by client-side validation, mirroring
|
|
33
|
+
* {@link CommandResult.validationFailed} so a caller reads a failed query the same way it reads a failed command.
|
|
34
|
+
* @param {ValidationResult[]} validationResults The validation results that caused the failure.
|
|
35
|
+
* @param {object} query The query being rejected, which describes how to shape its own result.
|
|
36
|
+
* @returns {QueryResult<TDataType>} A result that is neither successful nor valid.
|
|
37
|
+
*/ static validationFailed(validationResults, query) {
|
|
38
|
+
const { defaultValue, modelType, enumerable } = query;
|
|
39
|
+
return new QueryResult({
|
|
40
|
+
data: defaultValue,
|
|
41
|
+
isSuccess: false,
|
|
42
|
+
isAuthorized: true,
|
|
43
|
+
isValid: false,
|
|
44
|
+
hasExceptions: false,
|
|
45
|
+
validationResults: validationResults.map((_)=>({
|
|
46
|
+
severity: _.severity,
|
|
47
|
+
message: _.message,
|
|
48
|
+
members: _.members,
|
|
49
|
+
state: _.state
|
|
50
|
+
})),
|
|
51
|
+
exceptionMessages: [],
|
|
52
|
+
exceptionStackTrace: '',
|
|
53
|
+
paging: {
|
|
54
|
+
totalItems: 0,
|
|
55
|
+
totalPages: 0,
|
|
56
|
+
page: 0,
|
|
57
|
+
size: 0
|
|
58
|
+
}
|
|
59
|
+
}, modelType, enumerable);
|
|
60
|
+
}
|
|
31
61
|
static unauthorized() {
|
|
32
62
|
return new QueryResult({
|
|
33
63
|
data: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.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 { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\nimport { ChangeSet } from './ChangeSet';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n changeSet?: ServerChangeSet;\n}\n\ntype ServerChangeSet = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n added: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replaced: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n removed: any[];\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n let data: object = result.data;\n const isPrimitive = instanceType === String || instanceType === Number || instanceType === Boolean;\n if (enumerable) {\n if (Array.isArray(result.data)) {\n data = isPrimitive\n ? Array.from(result.data)\n : JsonSerializer.deserializeArrayFromInstance(instanceType, data);\n } else {\n data = [];\n }\n } else {\n data = isPrimitive ? data : JsonSerializer.deserializeFromInstance(instanceType, data);\n }\n\n this.data = data as TDataType;\n } else {\n this.data = (enumerable ? [] : null) as TDataType;\n }\n\n if (enumerable && result.changeSet) {\n const isPrimitive = instanceType === String || instanceType === Number || instanceType === Boolean;\n this.changeSet = {\n added: isPrimitive\n ? Array.from(result.changeSet.added ?? [])\n : JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.added ?? []),\n replaced: isPrimitive\n ? Array.from(result.changeSet.replaced ?? [])\n : JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.replaced ?? []),\n removed: isPrimitive\n ? Array.from(result.changeSet.removed ?? [])\n : JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.removed ?? []),\n } as ChangeSet<unknown>;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /**\n * Gets the optional change set describing what changed since the previous update.\n * Set by the server when the delta transfer mode is active.\n * When present, clients can apply the delta to their local state rather than replacing\n * the full dataset.\n */\n readonly changeSet?: ChangeSet<unknown>;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["QueryResult","empty","defaultValue","data","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","paging","totalItems","totalPages","page","size","Object","unauthorized","noSuccess","result","instanceType","enumerable","map","_","ValidationResult","severity","message","members","state","PagingInfo","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","changeSet","added","replaced","removed","hasData","length"],"mappings":";;;;;;AAAA;AACA;AA8CA;;;AAGC,IACM,MAAMA,WAAAA,CAAAA;IAET,OAAOC,KAAAA,CAAiBC,YAAuB,EAA0B;AACrE,QAAA,OAAO,IAAIF,WAAAA,CAAY;YACnBG,IAAAA,EAAMD,YAAAA;YACNE,SAAAA,EAAW,IAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,KAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;AACrBC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,mBAAAA,EAAqB,EAAA;YACrBC,MAAAA,EAAQ;gBACJC,UAAAA,EAAY,CAAA;gBACZC,UAAAA,EAAY,CAAA;gBACZC,IAAAA,EAAM,CAAA;gBACNC,IAAAA,EAAM;AACV;AAEJ,SAAA,EAAGC,MAAAA,EAAQ,KAAA,CAAA;AACf,IAAA;AAEA,IAAA,OAAOC,YAAAA,GAA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,mBAASC;AAET;;;;;AAKC,QACD,SAAS8B;AAET;;AAEC,QACD,IAAII,OAAAA,GAAmB;QACnB,IAAI,IAAI,CAACzC,IAAI,EAAE;AACX,YAAA,IAAI+B,MAAMC,OAAO,CAAC,IAAI,CAAChC,IAAI,CAAA,EAAG;AAC1B,gBAAA,OAAO,IAAI,CAACA,IAAI,CAAC0C,MAAM,GAAG,CAAA;AAC9B,YAAA;YACA,OAAO,IAAA;AACX,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.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 { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\nimport { ChangeSet } from './ChangeSet';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n changeSet?: ServerChangeSet;\n}\n\ntype ServerChangeSet = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n added: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replaced: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n removed: any[];\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n /**\n * Creates a {@link QueryResult} representing a query rejected by client-side validation, mirroring\n * {@link CommandResult.validationFailed} so a caller reads a failed query the same way it reads a failed command.\n * @param {ValidationResult[]} validationResults The validation results that caused the failure.\n * @param {object} query The query being rejected, which describes how to shape its own result.\n * @returns {QueryResult<TDataType>} A result that is neither successful nor valid.\n */\n static validationFailed<TDataType>(\n validationResults: ValidationResult[],\n query: { readonly defaultValue: TDataType; readonly modelType: Constructor; readonly enumerable: boolean }): QueryResult<TDataType> {\n const { defaultValue, modelType, enumerable } = query;\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, modelType, enumerable) as QueryResult<TDataType>;\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n let data: object = result.data;\n const isPrimitive = instanceType === String || instanceType === Number || instanceType === Boolean;\n if (enumerable) {\n if (Array.isArray(result.data)) {\n data = isPrimitive\n ? Array.from(result.data)\n : JsonSerializer.deserializeArrayFromInstance(instanceType, data);\n } else {\n data = [];\n }\n } else {\n data = isPrimitive ? data : JsonSerializer.deserializeFromInstance(instanceType, data);\n }\n\n this.data = data as TDataType;\n } else {\n this.data = (enumerable ? [] : null) as TDataType;\n }\n\n if (enumerable && result.changeSet) {\n const isPrimitive = instanceType === String || instanceType === Number || instanceType === Boolean;\n this.changeSet = {\n added: isPrimitive\n ? Array.from(result.changeSet.added ?? [])\n : JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.added ?? []),\n replaced: isPrimitive\n ? Array.from(result.changeSet.replaced ?? [])\n : JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.replaced ?? []),\n removed: isPrimitive\n ? Array.from(result.changeSet.removed ?? [])\n : JsonSerializer.deserializeArrayFromInstance(instanceType, result.changeSet.removed ?? []),\n } as ChangeSet<unknown>;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /**\n * Gets the optional change set describing what changed since the previous update.\n * Set by the server when the delta transfer mode is active.\n * When present, clients can apply the delta to their local state rather than replacing\n * the full dataset.\n */\n readonly changeSet?: ChangeSet<unknown>;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["QueryResult","empty","defaultValue","data","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","paging","totalItems","totalPages","page","size","Object","validationFailed","query","modelType","enumerable","map","_","severity","message","members","state","unauthorized","noSuccess","result","instanceType","ValidationResult","PagingInfo","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance","changeSet","added","replaced","removed","hasData","length"],"mappings":";;;;;;AAAA;AACA;AA8CA;;;AAGC,IACM,MAAMA,WAAAA,CAAAA;IAET,OAAOC,KAAAA,CAAiBC,YAAuB,EAA0B;AACrE,QAAA,OAAO,IAAIF,WAAAA,CAAY;YACnBG,IAAAA,EAAMD,YAAAA;YACNE,SAAAA,EAAW,IAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,KAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;AACrBC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,mBAAAA,EAAqB,EAAA;YACrBC,MAAAA,EAAQ;gBACJC,UAAAA,EAAY,CAAA;gBACZC,UAAAA,EAAY,CAAA;gBACZC,IAAAA,EAAM,CAAA;gBACNC,IAAAA,EA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AO,KAAA;AACX,IAAA;AACJ;;;;"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DataReceived } from './ObservableQueryConnection';
|
|
2
2
|
import { IObservableQueryConnection } from './IObservableQueryConnection';
|
|
3
|
+
import { QueryResult } from './QueryResult';
|
|
3
4
|
export declare class NullObservableQueryConnection<TDataType> implements IObservableQueryConnection<TDataType> {
|
|
4
5
|
readonly defaultValue: TDataType;
|
|
5
|
-
|
|
6
|
+
readonly result?: QueryResult<TDataType> | undefined;
|
|
7
|
+
constructor(defaultValue: TDataType, result?: QueryResult<TDataType> | undefined);
|
|
6
8
|
get lastPingLatency(): number;
|
|
7
9
|
get averageLatency(): number;
|
|
8
10
|
connect(dataReceived: DataReceived<TDataType>): void;
|
|
@@ -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;
|
|
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;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,qBAAa,6BAA6B,CAAC,SAAS,CAAE,YAAW,0BAA0B,CAAC,SAAS,CAAC;IAQtF,QAAQ,CAAC,YAAY,EAAE,SAAS;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC;IAAtF,YAAqB,YAAY,EAAE,SAAS,EAAW,MAAM,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,YAAA,EACrF;IAGD,IAAI,eAAe,IAAI,MAAM,CAE5B;IAGD,IAAI,cAAc,IAAI,MAAM,CAE3B;IAGD,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,SAAS,CAAC,QAE5C;IAID,UAAU,SACT;CACJ"}
|
|
@@ -6,11 +6,16 @@ import { QueryResult } from './QueryResult.js';
|
|
|
6
6
|
* Represents a {@link IObservableQueryConnection} when for instance one can't establish a connection.
|
|
7
7
|
*/ class NullObservableQueryConnection {
|
|
8
8
|
defaultValue;
|
|
9
|
+
result;
|
|
9
10
|
/**
|
|
10
11
|
* Initializes a new instance of the {@link NullObservableQueryConnection} class.
|
|
11
12
|
* @param {TDataType} defaultValue The default value to serve.
|
|
12
|
-
|
|
13
|
+
* @param {QueryResult<TDataType>} result Optional result to serve instead of an empty one. Supply it when the
|
|
14
|
+
* subscription failed for a reason the subscriber must be able to see — client-side validation in particular,
|
|
15
|
+
* which would otherwise be indistinguishable from a query that simply has no data yet.
|
|
16
|
+
*/ constructor(defaultValue, result){
|
|
13
17
|
this.defaultValue = defaultValue;
|
|
18
|
+
this.result = result;
|
|
14
19
|
}
|
|
15
20
|
/** @inheritdoc */ get lastPingLatency() {
|
|
16
21
|
return 0;
|
|
@@ -19,7 +24,7 @@ import { QueryResult } from './QueryResult.js';
|
|
|
19
24
|
return 0;
|
|
20
25
|
}
|
|
21
26
|
/** @inheritdoc */ connect(dataReceived) {
|
|
22
|
-
dataReceived(QueryResult.empty(this.defaultValue));
|
|
27
|
+
dataReceived(this.result ?? QueryResult.empty(this.defaultValue));
|
|
23
28
|
}
|
|
24
29
|
/** @inheritdoc */ /* eslint-disable @typescript-eslint/no-empty-function */ disconnect() {}
|
|
25
30
|
}
|
|
@@ -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 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":["NullObservableQueryConnection","defaultValue","lastPingLatency","averageLatency","connect","dataReceived","QueryResult","empty","disconnect"],"mappings":";;AAAA;AACA;AAMA;;AAEC,IAEM,MAAMA,6BAAAA,CAAAA
|
|
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 * @param {QueryResult<TDataType>} result Optional result to serve instead of an empty one. Supply it when the\n * subscription failed for a reason the subscriber must be able to see — client-side validation in particular,\n * which would otherwise be indistinguishable from a query that simply has no data yet.\n */\n constructor(readonly defaultValue: TDataType, readonly result?: QueryResult<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(this.result ?? QueryResult.empty(this.defaultValue));\n }\n\n /** @inheritdoc */\n /* eslint-disable @typescript-eslint/no-empty-function */\n disconnect() {\n }\n}\n"],"names":["NullObservableQueryConnection","result","defaultValue","lastPingLatency","averageLatency","connect","dataReceived","QueryResult","empty","disconnect"],"mappings":";;AAAA;AACA;AAMA;;AAEC,IAEM,MAAMA,6BAAAA,CAAAA;;;AACT;;;;;;AAMC,QACD,YAAY,YAAgC,EAAWC,MAA+B,CAAE;aAAnEC,YAAAA,GAAAA,YAAAA;aAAkCD,MAAAA,GAAAA,MAAAA;AACvD,IAAA;uBAGA,IAAIE,eAAAA,GAA0B;QAC1B,OAAO,CAAA;AACX,IAAA;uBAGA,IAAIC,cAAAA,GAAyB;QACzB,OAAO,CAAA;AACX,IAAA;uBAGAC,OAAAA,CAAQC,YAAqC,EAAE;QAC3CA,YAAAA,CAAa,IAAI,CAACL,MAAM,IAAIM,YAAYC,KAAK,CAAC,IAAI,CAACN,YAAY,CAAA,CAAA;AACnE,IAAA;AAEA,iFAEAO,UAAAA,GAAa,CACb;AACJ;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';
|
|
2
2
|
import { ObservableQuerySubscription } from './ObservableQuerySubscription';
|
|
3
|
+
import { QueryValidator } from './QueryValidator';
|
|
3
4
|
import { Constructor } from '@cratis/fundamentals';
|
|
4
5
|
import { QueryResult } from './QueryResult';
|
|
5
6
|
import { Sorting } from './Sorting';
|
|
@@ -19,6 +20,7 @@ export declare abstract class ObservableQueryFor<TDataType, TParameters = object
|
|
|
19
20
|
abstract readonly route: string;
|
|
20
21
|
abstract readonly defaultValue: TDataType;
|
|
21
22
|
readonly roles: string[];
|
|
23
|
+
readonly validation?: QueryValidator<any>;
|
|
22
24
|
readonly queryName?: string;
|
|
23
25
|
abstract readonly parameterDescriptors: ParameterDescriptor[];
|
|
24
26
|
abstract get requiredRequestParameters(): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.d.ts","sourceRoot":"","sources":["../../../queries/ObservableQueryFor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASpD,8BAAsB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,CAAE,YAAW,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC;IAwBhH,QAAQ,CAAC,SAAS,EAAE,WAAW;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO;IAvBzE,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO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B,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -27,6 +27,7 @@ import { executeQueryHttpRequest } from './QueryHttpRequest.js';
|
|
|
27
27
|
_httpHeadersCallback;
|
|
28
28
|
_httpMethod;
|
|
29
29
|
roles = [];
|
|
30
|
+
validation;
|
|
30
31
|
/** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */ queryName;
|
|
31
32
|
sorting;
|
|
32
33
|
paging;
|
|
@@ -68,7 +69,12 @@ import { executeQueryHttpRequest } from './QueryHttpRequest.js';
|
|
|
68
69
|
if (this._connection) {
|
|
69
70
|
this._connection.disconnect();
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
const clientValidationErrors = this.validation?.validate(args || {}) || [];
|
|
73
|
+
if (clientValidationErrors.length > 0) {
|
|
74
|
+
// Serve the failure through the connection rather than throwing, so a subscriber sees an invalid result
|
|
75
|
+
// on its normal callback path instead of the empty result an unestablished connection would emit.
|
|
76
|
+
this._connection = new NullObservableQueryConnection(this.defaultValue, QueryResult.validationFailed(clientValidationErrors, this));
|
|
77
|
+
} else if (!this.validateArguments(args)) {
|
|
72
78
|
this._connection = new NullObservableQueryConnection(this.defaultValue);
|
|
73
79
|
} else {
|
|
74
80
|
this._connection = createObservableQueryConnection({
|
|
@@ -114,6 +120,10 @@ import { executeQueryHttpRequest } from './QueryHttpRequest.js';
|
|
|
114
120
|
data: this.defaultValue
|
|
115
121
|
}
|
|
116
122
|
};
|
|
123
|
+
const clientValidationErrors = this.validation?.validate(args || {}) || [];
|
|
124
|
+
if (clientValidationErrors.length > 0) {
|
|
125
|
+
return QueryResult.validationFailed(clientValidationErrors, this);
|
|
126
|
+
}
|
|
117
127
|
if (!this.validateArguments(args)) {
|
|
118
128
|
return new Promise((resolve)=>{
|
|
119
129
|
resolve(noSuccess);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { createObservableQueryConnection } from './ObservableQueryConnectionFactory';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\nimport { QueryHttpMethod } from './QueryHttpMethod';\nimport { executeQueryHttpRequest } from './QueryHttpRequest';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n private _httpMethod?: QueryHttpMethod;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n readonly roles: string[] = [];\n /** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */\n readonly queryName?: string;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n setHttpMethod(method: QueryHttpMethod): void {\n this._httpMethod = method;\n }\n\n /** @inheritdoc */\n subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n this._connection = createObservableQueryConnection({\n route: this.route,\n queryName: this.queryName ?? this.constructor.name,\n origin: this._origin,\n apiBasePath: this._apiBasePath,\n microservice: this._microservice,\n args: args as object,\n });\n }\n\n // Descriptor-backed instance properties provide defaults; fresh args passed to subscribe()\n // must take precedence over any stale instance property values. Spread parameterValues\n // first so that the caller-supplied args can override them.\n //\n // In direct mode the route arguments are already embedded in the URL path, so only\n // the unused (non-route) parameters are appended as additional query arguments.\n // In multiplexed mode ALL arguments — including route-derived ones — must be included\n // in the subscribe payload so the server can execute the query correctly.\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...parameterValues,\n ...(Globals.queryDirectMode ? unusedParameters : (args as object) || {}),\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await executeQueryHttpRequest(this._httpMethod, {\n route: this.route,\n apiBasePath: this._apiBasePath,\n origin: this._origin,\n args: (args as object) ?? {},\n parameterValues,\n paging: this.paging,\n sorting: this.sorting,\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else if (result.data) {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["ObservableQueryFor","_microservice","_apiBasePath","_origin","_connection","_httpHeadersCallback","_httpMethod","roles","queryName","sorting","paging","enumerable","modelType","Sorting","none","Paging","noPaging","Globals","microservice","apiBasePath","origin","dispose","disconnect","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","setHttpMethod","method","subscribe","args","validateArguments","NullObservableQueryConnection","defaultValue","createObservableQueryConnection","route","name","parameterValues","ParametersHelper","collectParameterValues","unusedParameters","UrlHelpers","replaceRouteParameters","connectionQueryArguments","queryDirectMode","buildQueryArguments","subscriber","ObservableQuerySubscription","connect","data","result","deserializeResult","ex","console","log","perform","noSuccess","QueryResult","Promise","resolve","headers","length","microserviceHttpHeader","response","executeQueryHttpRequest","json","combinedArgs","ValidateRequestArguments","requiredRequestParameters","queryArguments","pageSize","page","hasSorting","sortBy","field","sortDirection","direction","SortDirection","descending","Array","isArray","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AAsBA;;;AAKC,IACM,MAAeA,kBAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,WAAAA;IACAC,oBAAAA;IACAC,WAAAA;AAICC,IAAAA,KAAAA,GAAkB,EAAE;sHAE7B,SAASC;IAGTC,OAAAA;IACAC,MAAAA;AAEA;;;;AAIC,QACD,YAAY,SAA+B,EAAWC,UAAmB,CAAE;aAAtDC,SAAAA,GAAAA,SAAAA;aAAiCD,UAAAA,GAAAA,UAAAA;AAClD,QAAA,IAAI,CAACF,OAAO,GAAGI,OAAAA,CAAQC,IAAI;AAC3B,QAAA,IAAI,CAACJ,MAAM,GAAGK,MAAAA,CAAOC,QAAQ;AAC7B,QAAA,IAAI,CAACf,aAAa,GAAGgB,OAAAA,CAAQC,YAAY,IAAI,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AAA,MAAO;gBACHC,MAAAA,CAAOD,IAAI,GAAG,EAAE;AACpB,YAAA;QACJ,CAAA,MAAO,IAAIC,MAAAA,CAAOD,IAAI,EAAE;YACpBC,MAAAA,CAAOD,IAAI,GAAGgC,cAAAA,CAAeE,uBAAuB,CAAC,IAAI,CAACxE,SAAS,EAAEuC,MAAAA,CAAOD,IAAI,CAAA;AACpF,QAAA;AACJ,IAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"ObservableQueryFor.js","sources":["../../../queries/ObservableQueryFor.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 { IObservableQueryFor, OnNextResult } from './IObservableQueryFor';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { QueryValidator } from './QueryValidator';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\nimport { createObservableQueryConnection } from './ObservableQueryConnectionFactory';\nimport { Constructor } from '@cratis/fundamentals';\nimport { JsonSerializer } from '@cratis/fundamentals';\nimport { QueryResult } from './QueryResult';\nimport { Sorting } from './Sorting';\nimport { Paging } from './Paging';\nimport { SortDirection } from './SortDirection';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\nimport { QueryHttpMethod } from './QueryHttpMethod';\nimport { executeQueryHttpRequest } from './QueryHttpRequest';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Represents an implementation of {@link IQueryFor}.\n * @template TDataType Type of data returned by the query.\n */\nexport abstract class ObservableQueryFor<TDataType, TParameters = object> implements IObservableQueryFor<TDataType, TParameters> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _connection?: IObservableQueryConnection<TDataType>;\n private _httpHeadersCallback: GetHttpHeaders;\n private _httpMethod?: QueryHttpMethod;\n\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\n readonly roles: string[] = [];\n readonly validation?: QueryValidator<any>;\n /** Backend fully-qualified query name used when subscribing via the SSE hub. Overridden in generated proxies. */\n readonly queryName?: string;\n abstract readonly parameterDescriptors: ParameterDescriptor[];\n abstract get requiredRequestParameters(): string[];\n sorting: Sorting;\n paging: Paging;\n\n /**\n * Initializes a new instance of the {@link ObservableQueryFor<,>}} class.\n * @param modelType Type of model, if an enumerable, this is the instance type.\n * @param enumerable Whether or not it is an enumerable.\n */\n constructor(readonly modelType: Constructor, readonly enumerable: boolean) {\n this.sorting = Sorting.none;\n this.paging = Paging.noPaging;\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /**\n * Disposes the query.\n */\n dispose() {\n this._connection?.disconnect();\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n setHttpMethod(method: QueryHttpMethod): void {\n this._httpMethod = method;\n }\n\n /** @inheritdoc */\n subscribe(callback: OnNextResult<QueryResult<TDataType>>, args?: TParameters): ObservableQuerySubscription<TDataType> {\n if (this._connection) {\n this._connection.disconnect();\n }\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n // Serve the failure through the connection rather than throwing, so a subscriber sees an invalid result\n // on its normal callback path instead of the empty result an unestablished connection would emit.\n this._connection = new NullObservableQueryConnection(\n this.defaultValue,\n QueryResult.validationFailed(clientValidationErrors, this));\n } else if (!this.validateArguments(args)) {\n this._connection = new NullObservableQueryConnection(this.defaultValue);\n } else {\n this._connection = createObservableQueryConnection({\n route: this.route,\n queryName: this.queryName ?? this.constructor.name,\n origin: this._origin,\n apiBasePath: this._apiBasePath,\n microservice: this._microservice,\n args: args as object,\n });\n }\n\n // Descriptor-backed instance properties provide defaults; fresh args passed to subscribe()\n // must take precedence over any stale instance property values. Spread parameterValues\n // first so that the caller-supplied args can override them.\n //\n // In direct mode the route arguments are already embedded in the URL path, so only\n // the unused (non-route) parameters are appended as additional query arguments.\n // In multiplexed mode ALL arguments — including route-derived ones — must be included\n // in the subscribe payload so the server can execute the query correctly.\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...parameterValues,\n ...(Globals.queryDirectMode ? unusedParameters : (args as object) || {}),\n ...this.buildQueryArguments()\n };\n\n const subscriber = new ObservableQuerySubscription(this._connection);\n this._connection.connect(data => {\n const result: any = data;\n try {\n this.deserializeResult(result);\n callback(result);\n } catch (ex) {\n console.log(ex);\n }\n }, connectionQueryArguments);\n return subscriber;\n }\n\n /** @inheritdoc */\n async perform(args?: TParameters): Promise<QueryResult<TDataType>> {\n const noSuccess = { ...QueryResult.noSuccess, ...{ data: this.defaultValue } } as QueryResult<TDataType>;\n\n const clientValidationErrors = this.validation?.validate(args as object || {}) || [];\n if (clientValidationErrors.length > 0) {\n return QueryResult.validationFailed(clientValidationErrors, this);\n }\n\n if (!this.validateArguments(args)) {\n return new Promise<QueryResult<TDataType>>((resolve) => {\n resolve(noSuccess);\n });\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const headers = {\n ...(this._httpHeadersCallback?.() || {}),\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n const response = await executeQueryHttpRequest(this._httpMethod, {\n route: this.route,\n apiBasePath: this._apiBasePath,\n origin: this._origin,\n args: (args as object) ?? {},\n parameterValues,\n paging: this.paging,\n sorting: this.sorting,\n headers\n });\n\n try {\n const result = await response.json();\n return new QueryResult(result, this.modelType, this.enumerable);\n } catch {\n return noSuccess;\n }\n }\n\n private validateArguments(args?: TParameters): boolean {\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const combinedArgs = { ...(args as object || {}), ...parameterValues };\n return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);\n }\n\n private buildQueryArguments(): any {\n const queryArguments: any = {};\n\n if (this.paging && this.paging.pageSize > 0) {\n queryArguments.pageSize = this.paging.pageSize;\n queryArguments.page = this.paging.page;\n }\n\n if (this.sorting.hasSorting) {\n queryArguments.sortBy = this.sorting.field;\n queryArguments.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n return queryArguments;\n }\n\n private deserializeResult(result: any): void {\n if (this.enumerable) {\n if (Array.isArray(result.data)) {\n result.data = JsonSerializer.deserializeArrayFromInstance(this.modelType, result.data);\n } else {\n result.data = [];\n }\n } else if (result.data) {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["ObservableQueryFor","_microservice","_apiBasePath","_origin","_connection","_httpHeadersCallback","_httpMethod","roles","validation","queryName","sorting","paging","enumerable","modelType","Sorting","none","Paging","noPaging","Globals","microservice","apiBasePath","origin","dispose","disconnect","setMicroservice","setApiBasePath","setOrigin","setHttpHeadersCallback","callback","setHttpMethod","method","subscribe","args","clientValidationErrors","validate","length","NullObservableQueryConnection","defaultValue","QueryResult","validationFailed","validateArguments","createObservableQueryConnection","route","name","parameterValues","ParametersHelper","collectParameterValues","unusedParameters","UrlHelpers","replaceRouteParameters","connectionQueryArguments","queryDirectMode","buildQueryArguments","subscriber","ObservableQuerySubscription","connect","data","result","deserializeResult","ex","console","log","perform","noSuccess","Promise","resolve","headers","microserviceHttpHeader","response","executeQueryHttpRequest","json","combinedArgs","ValidateRequestArguments","requiredRequestParameters","queryArguments","pageSize","page","hasSorting","sortBy","field","sortDirection","direction","SortDirection","descending","Array","isArray","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AAuBA;;;AAKC,IACM,MAAeA,kBAAAA,CAAAA;;;IACVC,aAAAA;IACAC,YAAAA;IACAC,OAAAA;IACAC,WAAAA;IACAC,oBAAAA;IACAC,WAAAA;AAICC,IAAAA,KAAAA,GAAkB,EAAE;IACpBC,UAAAA;sHAET,SAASC;IAGTC,OAAAA;IACAC,MAAAA;AAEA;;;;AAIC,QACD,YAAY,SAA+B,EAAWC,UAAmB,CAAE;aAAtDC,SAAAA,GAAAA,SAAAA;aAAiCD,UAAAA,GAAAA,UAAAA;AAClD,QAAA,IAAI,CAACF,OAAO,GAAGI,OAAAA,CAAQC,IAAI;AAC3B,QAAA,IAAI,CAACJ,MAAM,GAAGK,MAAAA,CAAOC,QAAQ;AAC7B,QAAA,IAAI,CAAChB,aAAa,GAAGiB,OAAAA,CAAQC,YAAY,IAAI,EAAA;AAC7C,QAAA,IAAI,CAACjB,YAAY,GAAGgB,OAAAA,CAAQE,WAAW,IAAI,EAAA;AAC3C,QAAA,IAAI,CAACjB,OAAO,GAAGe,OAAAA,CAAQG,MAAM,IAAI,EAAA;AACjC,QAAA,IAAI,CAAChB,oBAAoB,GAAG,KAAO,EAAC,CAAA;AACxC,IAAA;AAEA;;AAEC,QACDiB,OAAAA,GAAU;QACN,IAAI,CAAClB,WAAW,EAAEmB,UAAAA,EAAAA;AACtB,IAAA;uBAGAC,eAAAA,CAAgBL,YAAoB,EAAE;QAClC,IAAI,CAAClB,aAAa,GAAGkB,YAAAA;AACzB,IAAA;uBAGAM,cAAAA,CAAeL,WAAmB,EAAQ;QACtC,IAAI,CAAClB,YAAY,GAAGkB,WAAAA;AACxB,I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AAe,CAAC,YAAY,EAAE,MAAM,QAEnC;IAGD,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAExC;IAGD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9B;IAGD,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAErD;IAGD,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAE3C;IAGK,OAAO,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAuDjE;CACJ"}
|
|
@@ -65,27 +65,7 @@ import { executeQueryHttpRequest } from './QueryHttpRequest.js';
|
|
|
65
65
|
args = args || this.parameters;
|
|
66
66
|
const clientValidationErrors = this.validation?.validate(args || {}) || [];
|
|
67
67
|
if (clientValidationErrors.length > 0) {
|
|
68
|
-
return
|
|
69
|
-
data: this.defaultValue,
|
|
70
|
-
isSuccess: false,
|
|
71
|
-
isAuthorized: true,
|
|
72
|
-
isValid: false,
|
|
73
|
-
hasExceptions: false,
|
|
74
|
-
validationResults: clientValidationErrors.map((_)=>({
|
|
75
|
-
severity: _.severity,
|
|
76
|
-
message: _.message,
|
|
77
|
-
members: _.members,
|
|
78
|
-
state: _.state
|
|
79
|
-
})),
|
|
80
|
-
exceptionMessages: [],
|
|
81
|
-
exceptionStackTrace: '',
|
|
82
|
-
paging: {
|
|
83
|
-
totalItems: 0,
|
|
84
|
-
totalPages: 0,
|
|
85
|
-
page: 0,
|
|
86
|
-
size: 0
|
|
87
|
-
}
|
|
88
|
-
}, this.modelType, this.enumerable);
|
|
68
|
+
return QueryResult.validationFailed(clientValidationErrors, this);
|
|
89
69
|
}
|
|
90
70
|
if (!ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args)) {
|
|
91
71
|
return new Promise((resolve)=>{
|