@cratis/arc 18.7.8 → 18.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/cjs/queries/ObservableQueryFor.d.ts.map +1 -1
  2. package/dist/cjs/queries/ObservableQueryFor.js +3 -1
  3. package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
  4. package/dist/cjs/validation/RuleBuilderExtensions.d.ts +4 -0
  5. package/dist/cjs/validation/RuleBuilderExtensions.d.ts.map +1 -1
  6. package/dist/cjs/validation/RuleBuilderExtensions.js +14 -0
  7. package/dist/cjs/validation/RuleBuilderExtensions.js.map +1 -1
  8. package/dist/cjs/validation/index.js +2 -0
  9. package/dist/cjs/validation/index.js.map +1 -1
  10. package/dist/cjs/validation/rules/PhoneRule.d.ts +7 -0
  11. package/dist/cjs/validation/rules/PhoneRule.d.ts.map +1 -0
  12. package/dist/cjs/validation/rules/PhoneRule.js +19 -0
  13. package/dist/cjs/validation/rules/PhoneRule.js.map +1 -0
  14. package/dist/cjs/validation/rules/UrlRule.d.ts +7 -0
  15. package/dist/cjs/validation/rules/UrlRule.d.ts.map +1 -0
  16. package/dist/cjs/validation/rules/UrlRule.js +19 -0
  17. package/dist/cjs/validation/rules/UrlRule.js.map +1 -0
  18. package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
  19. package/dist/esm/queries/ObservableQueryFor.js +3 -1
  20. package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
  21. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  22. package/dist/esm/validation/RuleBuilderExtensions.d.ts +4 -0
  23. package/dist/esm/validation/RuleBuilderExtensions.d.ts.map +1 -1
  24. package/dist/esm/validation/RuleBuilderExtensions.js +13 -1
  25. package/dist/esm/validation/RuleBuilderExtensions.js.map +1 -1
  26. package/dist/esm/validation/index.js +1 -1
  27. package/dist/esm/validation/rules/PhoneRule.d.ts +7 -0
  28. package/dist/esm/validation/rules/PhoneRule.d.ts.map +1 -0
  29. package/dist/esm/validation/rules/PhoneRule.js +17 -0
  30. package/dist/esm/validation/rules/PhoneRule.js.map +1 -0
  31. package/dist/esm/validation/rules/UrlRule.d.ts +7 -0
  32. package/dist/esm/validation/rules/UrlRule.d.ts.map +1 -0
  33. package/dist/esm/validation/rules/UrlRule.js +17 -0
  34. package/dist/esm/validation/rules/UrlRule.js.map +1 -0
  35. package/package.json +1 -1
  36. package/queries/ObservableQueryFor.ts +3 -1
  37. package/validation/RuleBuilderExtensions.ts +28 -0
  38. package/validation/rules/PhoneRule.ts +28 -0
  39. package/validation/rules/UrlRule.ts +28 -0
@@ -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;AAE1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAI5E,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;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AASxE,8BAAsB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,CAAE,YAAW,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC;IAmBhH,QAAQ,CAAC,SAAS,EAAE,WAAW;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO;IAlBzE,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CA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AC,EAAE,WAAW,GAAG,2BAA2B,CAAC,SAAS,CAAC;IAqC/G,OAAO,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAyDlE,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,0BAA0B;IAsBlC,OAAO,CAAC,iBAAiB;CAW5B"}
@@ -128,7 +128,9 @@ class ObservableQueryFor {
128
128
  }
129
129
  }
130
130
  validateArguments(args) {
131
- return ValidateRequestArguments.ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args);
131
+ const parameterValues = ParametersHelper.ParametersHelper.collectParameterValues(this);
132
+ const combinedArgs = { ...(args || {}), ...parameterValues };
133
+ return ValidateRequestArguments.ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs);
132
134
  }
133
135
  buildRoute(args) {
134
136
  const { route } = UrlHelpers.UrlHelpers.replaceRouteParameters(this.route, args);
@@ -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 { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\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 { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\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\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\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 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 const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\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 const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\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 fetch(url, {\n method: 'GET',\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 return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object);\n }\n\n private buildRoute(args?: TParameters): string {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n return actualRoute;\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 addPagingAndSortingToRoute(route: string): string {\n const additionalParams: Record<string, string | number> = {};\n \n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n route += '?' + queryString;\n }\n \n return route;\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 {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["Sorting","Paging","Globals","NullObservableQueryConnection","UrlHelpers","joinPaths","ObservableQueryConnection","ParametersHelper","ObservableQuerySubscription","QueryResult","SortDirection","ValidateRequestArguments","JsonSerializer"],"mappings":";;;;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAmBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAlB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;AAM5B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAGC,aAAM,CAAC,QAAQ;QAC7B,IAAI,CAAC,aAAa,GAAGC,eAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAGA,eAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;IAKA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE;IAClC;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc,EAAA;AACpB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;IACzB;AAGA,IAAA,sBAAsB,CAAC,QAAwB,EAAA;AAC3C,QAAA,IAAI,CAAC,oBAAoB,GAAG,QAAQ;IACxC;IAGA,SAAS,CAAC,QAA8C,EA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a,CAAC,UAAU,IAAI,MAAM,GAAG,KAAK;QAC3G;QAEA,MAAM,WAAW,GAAGN,qBAAU,CAAC,gBAAgB,CAAC,EAAE,EAAE,gBAAgB,CAAC;AACrE,QAAA,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE;QAC1C,IAAI,WAAW,EAAE;AACb,YAAA,KAAK,IAAI,GAAG,GAAG,WAAW;QAC9B;AAEA,QAAA,OAAO,KAAK;IAChB;AAEQ,IAAA,iBAAiB,CAAC,MAAW,EAAA;AACjC,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,MAAM,CAAC,IAAI,GAAGQ,2BAAc,CAAC,4BAA4B,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;YAC1F;iBAAO;AACH,gBAAA,MAAM,CAAC,IAAI,GAAG,EAAE;YACpB;QACJ;aAAO;AACH,YAAA,MAAM,CAAC,IAAI,GAAGA,2BAAc,CAAC,uBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;QACrF;IACJ;AACH;;;;"}
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 { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\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 { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\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\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\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 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 const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\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 const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\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 fetch(url, {\n method: 'GET',\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 buildRoute(args?: TParameters): string {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n return actualRoute;\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 addPagingAndSortingToRoute(route: string): string {\n const additionalParams: Record<string, string | number> = {};\n \n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n route += '?' + queryString;\n }\n \n return route;\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 {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":["Sorting","Paging","Globals","NullObservableQueryConnection","UrlHelpers","joinPaths","ObservableQueryConnection","ParametersHelper","ObservableQuerySubscription","QueryResult","SortDirection","ValidateRequestArguments","JsonSerializer"],"mappings":";;;;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAmBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAlB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;AAM5B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAGC,aAAM,CAAC,QAAQ;QAC7B,IAAI,CAAC,aAAa,GAAGC,eAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAGA,eAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;IAKA,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE;IAClC;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc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YACvB,gBAAgB,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI;YACxC,gBAAgB,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ;QACpD;AAEA,QAAA,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YACzB,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;YAC5C,gBAAgB,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,KAAKA,2BAAa,CAAC,UAAU,IAAI,MAAM,GAAG,KAAK;QAC3G;QAEA,MAAM,WAAW,GAAGN,qBAAU,CAAC,gBAAgB,CAAC,EAAE,EAAE,gBAAgB,CAAC;AACrE,QAAA,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,EAAE;QAC1C,IAAI,WAAW,EAAE;AACb,YAAA,KAAK,IAAI,GAAG,GAAG,WAAW;QAC9B;AAEA,QAAA,OAAO,KAAK;IAChB;AAEQ,IAAA,iBAAiB,CAAC,MAAW,EAAA;AACjC,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,MAAM,CAAC,IAAI,GAAGQ,2BAAc,CAAC,4BAA4B,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;YAC1F;iBAAO;AACH,gBAAA,MAAM,CAAC,IAAI,GAAG,EAAE;YACpB;QACJ;aAAO;AACH,YAAA,MAAM,CAAC,IAAI,GAAGA,2BAAc,CAAC,uBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;QACrF;IACJ;AACH;;;;"}
@@ -5,6 +5,8 @@ export declare function minLength<T>(this: RuleBuilder<T, string>, length: numbe
5
5
  export declare function maxLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string>;
6
6
  export declare function length<T>(this: RuleBuilder<T, string>, min: number, max: number): RuleBuilder<T, string>;
7
7
  export declare function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string>;
8
+ export declare function phone<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string>;
9
+ export declare function url<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string>;
8
10
  export declare function matches<T>(this: RuleBuilder<T, string>, pattern: RegExp, errorMessage?: string): RuleBuilder<T, string>;
9
11
  export declare function greaterThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number>;
10
12
  export declare function greaterThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number>;
@@ -18,6 +20,8 @@ declare module './RuleBuilder' {
18
20
  maxLength(length: number): RuleBuilder<T, TProperty>;
19
21
  length(min: number, max: number): RuleBuilder<T, TProperty>;
20
22
  emailAddress(): RuleBuilder<T, TProperty>;
23
+ phone(): RuleBuilder<T, TProperty>;
24
+ url(): RuleBuilder<T, TProperty>;
21
25
  matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;
22
26
  greaterThan(threshold: number): RuleBuilder<T, TProperty>;
23
27
  greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;
@@ -1 +1 @@
1
- {"version":3,"file":"RuleBuilderExtensions.d.ts","sourceRoot":"","sources":["../../../validation/RuleBuilderExtensions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkB5C,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAGjG;AASD,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAGhG;AASD,wBAAgB,SAAS,CAAC,CAA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AM,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC5D,YAAY,IAAI,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC1C,KAAK,IAAI,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACnC,GAAG,IAAI,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACjC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC3E,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QAC1D,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACjE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACvD,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;KACjE;CACJ"}
@@ -4,6 +4,8 @@ var RuleBuilder = require('./RuleBuilder.js');
4
4
  var NotEmptyRule = require('./rules/NotEmptyRule.js');
5
5
  var LengthRules = require('./rules/LengthRules.js');
6
6
  var EmailRule = require('./rules/EmailRule.js');
7
+ var PhoneRule = require('./rules/PhoneRule.js');
8
+ var UrlRule = require('./rules/UrlRule.js');
7
9
  var RegexRule = require('./rules/RegexRule.js');
8
10
  var ComparisonRules = require('./rules/ComparisonRules.js');
9
11
 
@@ -31,6 +33,14 @@ function emailAddress() {
31
33
  const propertyAccessor = this._propertyAccessor;
32
34
  return this.addRule(new EmailRule.EmailRule(propertyAccessor));
33
35
  }
36
+ function phone() {
37
+ const propertyAccessor = this._propertyAccessor;
38
+ return this.addRule(new PhoneRule.PhoneRule(propertyAccessor));
39
+ }
40
+ function url() {
41
+ const propertyAccessor = this._propertyAccessor;
42
+ return this.addRule(new UrlRule.UrlRule(propertyAccessor));
43
+ }
34
44
  function matches(pattern, errorMessage) {
35
45
  const propertyAccessor = this._propertyAccessor;
36
46
  return this.addRule(new RegexRule.RegexRule(propertyAccessor, pattern, errorMessage));
@@ -57,6 +67,8 @@ RuleBuilder.RuleBuilder.prototype.minLength = minLength;
57
67
  RuleBuilder.RuleBuilder.prototype.maxLength = maxLength;
58
68
  RuleBuilder.RuleBuilder.prototype.length = length;
59
69
  RuleBuilder.RuleBuilder.prototype.emailAddress = emailAddress;
70
+ RuleBuilder.RuleBuilder.prototype.phone = phone;
71
+ RuleBuilder.RuleBuilder.prototype.url = url;
60
72
  RuleBuilder.RuleBuilder.prototype.matches = matches;
61
73
  RuleBuilder.RuleBuilder.prototype.greaterThan = greaterThan;
62
74
  RuleBuilder.RuleBuilder.prototype.greaterThanOrEqual = greaterThanOrEqual;
@@ -74,4 +86,6 @@ exports.maxLength = maxLength;
74
86
  exports.minLength = minLength;
75
87
  exports.notEmpty = notEmpty;
76
88
  exports.notNull = notNull;
89
+ exports.phone = phone;
90
+ exports.url = url;
77
91
  //# sourceMappingURL=RuleBuilderExtensions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RuleBuilderExtensions.js","sources":["../../../validation/RuleBuilderExtensions.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 { RuleBuilder } from './RuleBuilder';\nimport { NotEmptyRule, NotNullRule } from './rules/NotEmptyRule';\nimport { MinLengthRule, MaxLengthRule, LengthRule } from './rules/LengthRules';\nimport { EmailRule } from './rules/EmailRule';\nimport { RegexRule } from './rules/RegexRule';\nimport { GreaterThanRule, GreaterThanOrEqualRule, LessThanRule, LessThanOrEqualRule } from './rules/ComparisonRules';\n\n/**\n * Extension methods for {@link RuleBuilder} to add validation rules in a fluent manner.\n */\n\n/**\n * Add a rule that the property must not be empty (not null, undefined, empty string, or empty array).\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notEmpty<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotEmptyRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the property must not be null or undefined.\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notNull<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotNullRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must have at least the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The minimum length.\n * @returns The rule builder for chaining.\n */\nexport function minLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MinLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have at most the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function maxLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MaxLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have a length between min and max.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param min The minimum length.\n * @param max The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function length<T>(this: RuleBuilder<T, string>, min: number, max: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new LengthRule<T>(propertyAccessor, min, max));\n}\n\n/**\n * Add a rule that the string property must be a valid email address.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new EmailRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must match the specified regular expression.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param pattern The regular expression pattern.\n * @param errorMessage Optional error message.\n * @returns The rule builder for chaining.\n */\nexport function matches<T>(this: RuleBuilder<T, string>, pattern: RegExp, errorMessage?: string): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new RegexRule<T>(propertyAccessor, pattern, errorMessage));\n}\n\n/**\n * Add a rule that the number property must be greater than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be greater than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n// Add the extension methods to the RuleBuilder prototype\nRuleBuilder.prototype.notEmpty = notEmpty;\nRuleBuilder.prototype.notNull = notNull;\n(RuleBuilder.prototype as unknown as { minLength: typeof minLength }).minLength = minLength;\n(RuleBuilder.prototype as unknown as { maxLength: typeof maxLength }).maxLength = maxLength;\n(RuleBuilder.prototype as unknown as { length: typeof length }).length = length;\n(RuleBuilder.prototype as unknown as { emailAddress: typeof emailAddress }).emailAddress = emailAddress;\n(RuleBuilder.prototype as unknown as { matches: typeof matches }).matches = matches;\n(RuleBuilder.prototype as unknown as { greaterThan: typeof greaterThan }).greaterThan = greaterThan;\n(RuleBuilder.prototype as unknown as { greaterThanOrEqual: typeof greaterThanOrEqual }).greaterThanOrEqual = greaterThanOrEqual;\n(RuleBuilder.prototype as unknown as { lessThan: typeof lessThan }).lessThan = lessThan;\n(RuleBuilder.prototype as unknown as { lessThanOrEqual: typeof lessThanOrEqual }).lessThanOrEqual = lessThanOrEqual;\n\n// Extend the RuleBuilder interface to include these methods\ndeclare module './RuleBuilder' {\n interface RuleBuilder<T, TProperty> {\n notEmpty(): RuleBuilder<T, TProperty>;\n notNull(): RuleBuilder<T, TProperty>;\n minLength(length: number): RuleBuilder<T, TProperty>;\n maxLength(length: number): RuleBuilder<T, TProperty>;\n length(min: number, max: number): RuleBuilder<T, TProperty>;\n emailAddress(): RuleBuilder<T, TProperty>;\n matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;\n greaterThan(threshold: number): RuleBuilder<T, TProperty>;\n greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n lessThan(threshold: number): RuleBuilder<T, TProperty>;\n lessThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n }\n}\n"],"names":["NotEmptyRule","NotNullRule","MinLengthRule","MaxLengthRule","LengthRule","EmailRule","RegexRule","GreaterThanRule","GreaterThanOrEqualRule","LessThanRule","LessThanOrEqualRule","RuleBuilder"],"mappings":";;;;;;;;;SAqBgB,QAAQ,GAAA;AACpB,IAAA,MAAM,gBAAgB,GAAI,IAAqE,CAAC,iBAAiB;IACjH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAIA,yBAAY,CAAI,gBAAgB,CAAC,CAAC;AAC9D;SASgB,OAAO,GAAA;AACnB,IAAA,MAAM,gBAAgB,GAAI,IAAqE,CAAC,iBAAiB;IACjH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAIC,wBAAW,CAAI,gBAAgB,CAAC,CAAC;AAC7D;AASM,SAAU,SAAS,CAAkC,MAAc,EAAA;AACrE,IAAA,MAAM,gBAAgB,GAAI,IAAkE,CAAC,iBAAiB;AAC9G,IAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAIC,yBAAa,CAAI,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACvE;AASM,SAAU,SAAS,CAAkC,MAAc,EAAA;AACrE,IAAA,MAAM,gBAAgB,GAAI,IAAkE,CAAC,iBAAiB;AAC9G,IAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAIC,yBAAa,CAAI,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACvE;AAUM,SAAU,MAAM,CAAkC,GAAW,EAAE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C,iBAAiB;AAC9G,IAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAIC,mCAAmB,CAAI,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAChF;AAGAC,uBAAW,CAAC,SAAS,CAAC,QAAQ,GAAG,QAAQ;AACzCA,uBAAW,CAAC,SAAS,CAAC,OAAO,GAAG,OAAO;AACtCA,uBAAW,CAAC,SAAwD,CAAC,SAAS,GAAG,SAAS;AAC1FA,uBAAW,CAAC,SAAwD,CAAC,SAAS,GAAG,SAAS;AAC1FA,uBAAW,CAAC,SAAkD,CAAC,MAAM,GAAG,MAAM;AAC9EA,uBAAW,CAAC,SAA8D,CAAC,YAAY,GAAG,YAAY;AACtGA,uBAAW,CAAC,SAAoD,CAAC,OAAO,GAAG,OAAO;AAClFA,uBAAW,CAAC,SAA4D,CAAC,WAAW,GAAG,WAAW;AAClGA,uBAAW,CAAC,SAA0E,CAAC,kBAAkB,GAAG,kBAAkB;AAC9HA,uBAAW,CAAC,SAAsD,CAAC,QAAQ,GAAG,QAAQ;AACtFA,uBAAW,CAAC,SAAoE,CAAC,eAAe,GAAG,eAAe;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"RuleBuilderExtensions.js","sources":["../../../validation/RuleBuilderExtensions.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 { RuleBuilder } from './RuleBuilder';\nimport { NotEmptyRule, NotNullRule } from './rules/NotEmptyRule';\nimport { MinLengthRule, MaxLengthRule, LengthRule } from './rules/LengthRules';\nimport { EmailRule } from './rules/EmailRule';\nimport { PhoneRule } from './rules/PhoneRule';\nimport { UrlRule } from './rules/UrlRule';\nimport { RegexRule } from './rules/RegexRule';\nimport { GreaterThanRule, GreaterThanOrEqualRule, LessThanRule, LessThanOrEqualRule } from './rules/ComparisonRules';\n\n/**\n * Extension methods for {@link RuleBuilder} to add validation rules in a fluent manner.\n */\n\n/**\n * Add a rule that the property must not be empty (not null, undefined, empty string, or empty array).\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notEmpty<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotEmptyRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the property must not be null or undefined.\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notNull<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotNullRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must have at least the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The minimum length.\n * @returns The rule builder for chaining.\n */\nexport function minLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MinLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have at most the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function maxLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MaxLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have a length between min and max.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param min The minimum length.\n * @param max The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function length<T>(this: RuleBuilder<T, string>, min: number, max: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new LengthRule<T>(propertyAccessor, min, max));\n}\n\n/**\n * Add a rule that the string property must be a valid email address.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new EmailRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must be a valid phone number.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function phone<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new PhoneRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must be a valid URL.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function url<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new UrlRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must match the specified regular expression.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param pattern The regular expression pattern.\n * @param errorMessage Optional error message.\n * @returns The rule builder for chaining.\n */\nexport function matches<T>(this: RuleBuilder<T, string>, pattern: RegExp, errorMessage?: string): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new RegexRule<T>(propertyAccessor, pattern, errorMessage));\n}\n\n/**\n * Add a rule that the number property must be greater than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be greater than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n// Add the extension methods to the RuleBuilder prototype\nRuleBuilder.prototype.notEmpty = notEmpty;\nRuleBuilder.prototype.notNull = notNull;\n(RuleBuilder.prototype as unknown as { minLength: typeof minLength }).minLength = minLength;\n(RuleBuilder.prototype as unknown as { maxLength: typeof maxLength }).maxLength = maxLength;\n(RuleBuilder.prototype as unknown as { length: typeof length }).length = length;\n(RuleBuilder.prototype as unknown as { emailAddress: typeof emailAddress }).emailAddress = emailAddress;\n(RuleBuilder.prototype as unknown as { phone: typeof phone }).phone = phone;\n(RuleBuilder.prototype as unknown as { url: typeof url }).url = url;\n(RuleBuilder.prototype as unknown as { matches: typeof matches }).matches = matches;\n(RuleBuilder.prototype as unknown as { greaterThan: typeof greaterThan }).greaterThan = greaterThan;\n(RuleBuilder.prototype as unknown as { greaterThanOrEqual: typeof greaterThanOrEqual }).greaterThanOrEqual = greaterThanOrEqual;\n(RuleBuilder.prototype as unknown as { lessThan: typeof lessThan }).lessThan = lessThan;\n(RuleBuilder.prototype as unknown as { lessThanOrEqual: typeof lessThanOrEqual }).lessThanOrEqual = lessThanOrEqual;\n\n// Extend the RuleBuilder interface to include these methods\ndeclare module './RuleBuilder' {\n interface RuleBuilder<T, TProperty> {\n notEmpty(): RuleBuilder<T, TProperty>;\n notNull(): RuleBuilder<T, TProperty>;\n minLength(length: number): RuleBuilder<T, TProperty>;\n maxLength(length: number): RuleBuilder<T, TProperty>;\n length(min: number, max: number): RuleBuilder<T, TProperty>;\n emailAddress(): RuleBuilder<T, TProperty>;\n phone(): RuleBuilder<T, TProperty>;\n url(): RuleBuilder<T, TProperty>;\n matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;\n greaterThan(threshold: number): RuleBuilder<T, TProperty>;\n greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n lessThan(threshold: number): RuleBuilder<T, TProperty>;\n lessThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n }\n}\n"],"names":["NotEmptyRule","NotNullRule","MinLengthRule","MaxLengthRule","LengthRule","EmailRule","PhoneRule","UrlRule","RegexRule","GreaterThanRule","GreaterThanOrEqualRule","LessThanRule","LessThanOrEqualRule","RuleBuilder"],"mappings":";;;;;;;;;;;SAuBgB,QAAQ,GAAA;AACpB,IAAA,MAAM,gBAAgB,GAAI,IAAqE,CAAC,iBAAiB;IACjH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAIA,yBAAY,CAAI,gBAAgB,CAAC,CAAC;AAC9D;SASgB,OAAO,GAAA;AACnB,IAAA,MAAM,gBAAgB,GAAI,IAAqE,CAAC,iBAA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,YAAY,GAAG,YAAY;AACtGA,uBAAW,CAAC,SAAgD,CAAC,KAAK,GAAG,KAAK;AAC1EA,uBAAW,CAAC,SAA4C,CAAC,GAAG,GAAG,GAAG;AAClEA,uBAAW,CAAC,SAAoD,CAAC,OAAO,GAAG,OAAO;AAClFA,uBAAW,CAAC,SAA4D,CAAC,WAAW,GAAG,WAAW;AAClGA,uBAAW,CAAC,SAA0E,CAAC,kBAAkB,GAAG,kBAAkB;AAC9HA,uBAAW,CAAC,SAAsD,CAAC,QAAQ,GAAG,QAAQ;AACtFA,uBAAW,CAAC,SAAoE,CAAC,eAAe,GAAG,eAAe;;;;;;;;;;;;;;;;"}
@@ -35,6 +35,8 @@ exports.maxLength = RuleBuilderExtensions.maxLength;
35
35
  exports.minLength = RuleBuilderExtensions.minLength;
36
36
  exports.notEmpty = RuleBuilderExtensions.notEmpty;
37
37
  exports.notNull = RuleBuilderExtensions.notNull;
38
+ exports.phone = RuleBuilderExtensions.phone;
39
+ exports.url = RuleBuilderExtensions.url;
38
40
  exports.NotEmptyRule = NotEmptyRule.NotEmptyRule;
39
41
  exports.NotNullRule = NotEmptyRule.NotNullRule;
40
42
  exports.LengthRule = LengthRules.LengthRule;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,7 @@
1
+ import { PropertyRule } from '../PropertyRule';
2
+ export declare class PhoneRule<T> extends PropertyRule<T, string> {
3
+ private static readonly phoneRegex;
4
+ constructor(propertyAccessor: (instance: T) => string);
5
+ protected isValid(value: string): boolean;
6
+ }
7
+ //# sourceMappingURL=PhoneRule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhoneRule.d.ts","sourceRoot":"","sources":["../../../../validation/rules/PhoneRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/C,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAmB;gBAMzC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM;IAKrD,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAM5C"}
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var PropertyRule = require('../PropertyRule.js');
4
+
5
+ class PhoneRule extends PropertyRule.PropertyRule {
6
+ static phoneRegex = /^[\d\s()+-]+$/;
7
+ constructor(propertyAccessor) {
8
+ super(propertyAccessor, "'{PropertyName}' is not a valid phone number.");
9
+ }
10
+ isValid(value) {
11
+ if (value === null || value === undefined || value === '') {
12
+ return true;
13
+ }
14
+ return PhoneRule.phoneRegex.test(value);
15
+ }
16
+ }
17
+
18
+ exports.PhoneRule = PhoneRule;
19
+ //# sourceMappingURL=PhoneRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhoneRule.js","sources":["../../../../validation/rules/PhoneRule.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 { PropertyRule } from '../PropertyRule';\n\n/**\n * Validation rule that checks if a string matches a phone number pattern.\n * @template T The type being validated.\n */\nexport class PhoneRule<T> extends PropertyRule<T, string> {\n private static readonly phoneRegex = /^[\\d\\s()+-]+$/;\n\n /**\n * Initializes a new instance of the {@link PhoneRule} class.\n * @param propertyAccessor Function to access the property value from the instance.\n */\n constructor(propertyAccessor: (instance: T) => string) {\n super(propertyAccessor, \"'{PropertyName}' is not a valid phone number.\");\n }\n\n /** @inheritdoc */\n protected isValid(value: string): boolean {\n if (value === null || value === undefined || value === '') {\n return true; // Use NotNull/NotEmpty for null checks\n }\n return PhoneRule.phoneRegex.test(value);\n }\n}\n"],"names":["PropertyRule"],"mappings":";;;;AASM,MAAO,SAAa,SAAQA,yBAAuB,CAAA;AAC7C,IAAA,OAAgB,UAAU,GAAG,eAAe;AAMpD,IAAA,WAAA,CAAY,gBAAyC,EAAA;AACjD,QAAA,KAAK,CAAC,gBAAgB,EAAE,+CAA+C,CAAC;IAC5E;AAGU,IAAA,OAAO,CAAC,KAAa,EAAA;AAC3B,QAAA,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE;AACvD,YAAA,OAAO,IAAI;QACf;QACA,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;IAC3C;;;;;"}
@@ -0,0 +1,7 @@
1
+ import { PropertyRule } from '../PropertyRule';
2
+ export declare class UrlRule<T> extends PropertyRule<T, string> {
3
+ private static readonly urlRegex;
4
+ constructor(propertyAccessor: (instance: T) => string);
5
+ protected isValid(value: string): boolean;
6
+ }
7
+ //# sourceMappingURL=UrlRule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UrlRule.d.ts","sourceRoot":"","sources":["../../../../validation/rules/UrlRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/C,qBAAa,OAAO,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;IACnD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAqB;gBAMzC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM;IAKrD,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAM5C"}
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var PropertyRule = require('../PropertyRule.js');
4
+
5
+ class UrlRule extends PropertyRule.PropertyRule {
6
+ static urlRegex = /^https?:\/\/.+/i;
7
+ constructor(propertyAccessor) {
8
+ super(propertyAccessor, "'{PropertyName}' is not a valid URL.");
9
+ }
10
+ isValid(value) {
11
+ if (value === null || value === undefined || value === '') {
12
+ return true;
13
+ }
14
+ return UrlRule.urlRegex.test(value);
15
+ }
16
+ }
17
+
18
+ exports.UrlRule = UrlRule;
19
+ //# sourceMappingURL=UrlRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UrlRule.js","sources":["../../../../validation/rules/UrlRule.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 { PropertyRule } from '../PropertyRule';\n\n/**\n * Validation rule that checks if a string is a valid URL.\n * @template T The type being validated.\n */\nexport class UrlRule<T> extends PropertyRule<T, string> {\n private static readonly urlRegex = /^https?:\\/\\/.+/i;\n\n /**\n * Initializes a new instance of the {@link UrlRule} class.\n * @param propertyAccessor Function to access the property value from the instance.\n */\n constructor(propertyAccessor: (instance: T) => string) {\n super(propertyAccessor, \"'{PropertyName}' is not a valid URL.\");\n }\n\n /** @inheritdoc */\n protected isValid(value: string): boolean {\n if (value === null || value === undefined || value === '') {\n return true; // Use NotNull/NotEmpty for null checks\n }\n return UrlRule.urlRegex.test(value);\n }\n}\n"],"names":["PropertyRule"],"mappings":";;;;AASM,MAAO,OAAW,SAAQA,yBAAuB,CAAA;AAC3C,IAAA,OAAgB,QAAQ,GAAG,iBAAiB;AAMpD,IAAA,WAAA,CAAY,gBAAyC,EAAA;AACjD,QAAA,KAAK,CAAC,gBAAgB,EAAE,sCAAsC,CAAC;IACnE;AAGU,IAAA,OAAO,CAAC,KAAa,EAAA;AAC3B,QAAA,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE;AACvD,YAAA,OAAO,IAAI;QACf;QACA,OAAO,OAAO,CAAC,QAAQ,CAAC,I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
129
- return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args);
129
+ const parameterValues = ParametersHelper.collectParameterValues(this);
130
+ const combinedArgs = { ...(args || {}), ...parameterValues };
131
+ return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs);
130
132
  }
131
133
  buildRoute(args) {
132
134
  const { route } = UrlHelpers.replaceRouteParameters(this.route, args);
@@ -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 { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\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 { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\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\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\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 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 const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\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 const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\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 fetch(url, {\n method: 'GET',\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 return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, args as object);\n }\n\n private buildRoute(args?: TParameters): string {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n return actualRoute;\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 addPagingAndSortingToRoute(route: string): string {\n const additionalParams: Record<string, string | number> = {};\n \n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n route += '?' + queryString;\n }\n \n return route;\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 {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAmBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAlB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;AAM5B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAA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CAAC,IAAI,GAAG,EAAE;YACpB;QACJ;aAAO;AACH,YAAA,MAAM,CAAC,IAAI,GAAG,cAAc,CAAC,uBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;QACrF;IACJ;AACH;;;;"}
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 { ObservableQueryConnection } from './ObservableQueryConnection';\nimport { ObservableQuerySubscription } from './ObservableQuerySubscription';\nimport { ValidateRequestArguments } from './ValidateRequestArguments';\nimport { IObservableQueryConnection } from './IObservableQueryConnection';\nimport { NullObservableQueryConnection } from './NullObservableQueryConnection';\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 { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor';\nimport { ParametersHelper } from '../reflection/ParametersHelper';\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\n abstract readonly route: string;\n abstract readonly defaultValue: TDataType;\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 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 const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n this._connection = new ObservableQueryConnection<TDataType>(url, this._microservice);\n }\n\n // Build query arguments including unused args parameters, parameter descriptor values, and paging/sorting\n const parameterValues = ParametersHelper.collectParameterValues(this);\n const { unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const connectionQueryArguments: any = {\n ...unusedParameters,\n ...parameterValues,\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 const { route, unusedParameters } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n let actualRoute = joinPaths(this._apiBasePath, route);\n \n const additionalParams: Record<string, string | number> = {};\n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n // Collect parameter values from parameterDescriptors that are set\n const parameterValues = ParametersHelper.collectParameterValues(this);\n\n const queryParams = UrlHelpers.buildQueryParams({ ...unusedParameters, ...parameterValues }, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n actualRoute += (actualRoute.includes('?') ? '&' : '?') + queryString;\n }\n\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\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 fetch(url, {\n method: 'GET',\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 buildRoute(args?: TParameters): string {\n const { route } = UrlHelpers.replaceRouteParameters(this.route, args as object);\n const actualRoute = joinPaths(this._apiBasePath, route);\n return actualRoute;\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 addPagingAndSortingToRoute(route: string): string {\n const additionalParams: Record<string, string | number> = {};\n \n if (this.paging.hasPaging) {\n additionalParams.page = this.paging.page;\n additionalParams.pageSize = this.paging.pageSize;\n }\n\n if (this.sorting.hasSorting) {\n additionalParams.sortBy = this.sorting.field;\n additionalParams.sortDirection = (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc';\n }\n\n const queryParams = UrlHelpers.buildQueryParams({}, additionalParams);\n const queryString = queryParams.toString();\n if (queryString) {\n route += '?' + queryString;\n }\n \n return route;\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 {\n result.data = JsonSerializer.deserializeFromInstance(this.modelType, result.data);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;MA4BsB,kBAAkB,CAAA;AAmBf,IAAA,SAAA;AAAiC,IAAA,UAAA;AAlB9C,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,WAAW;AACX,IAAA,oBAAoB;AAM5B,IAAA,OAAO;AACP,IAAA,MAAM;IAON,WAAA,CAAqB,SAAsB,EAAW,UAAmB,EAAA;QAApD,IAAA,CAAA,SAAS,GAAT,SAAS;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;AAC5D,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,QA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