@cratis/arc 18.7.18 → 18.7.20

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 (38) hide show
  1. package/commands/Command.ts +25 -16
  2. package/commands/index.ts +1 -0
  3. package/dist/cjs/commands/Command.d.ts +0 -1
  4. package/dist/cjs/commands/Command.d.ts.map +1 -1
  5. package/dist/cjs/commands/Command.js +20 -10
  6. package/dist/cjs/commands/Command.js.map +1 -1
  7. package/dist/cjs/commands/index.d.ts +1 -0
  8. package/dist/cjs/commands/index.d.ts.map +1 -1
  9. package/dist/cjs/commands/index.js +2 -0
  10. package/dist/cjs/commands/index.js.map +1 -1
  11. package/dist/cjs/queries/index.d.ts +1 -0
  12. package/dist/cjs/queries/index.d.ts.map +1 -1
  13. package/dist/cjs/queries/index.js +2 -0
  14. package/dist/cjs/queries/index.js.map +1 -1
  15. package/dist/cjs/reflection/PropertyDescriptor.d.ts +2 -1
  16. package/dist/cjs/reflection/PropertyDescriptor.d.ts.map +1 -1
  17. package/dist/cjs/reflection/PropertyDescriptor.js +3 -1
  18. package/dist/cjs/reflection/PropertyDescriptor.js.map +1 -1
  19. package/dist/esm/commands/Command.d.ts +0 -1
  20. package/dist/esm/commands/Command.d.ts.map +1 -1
  21. package/dist/esm/commands/Command.js +20 -10
  22. package/dist/esm/commands/Command.js.map +1 -1
  23. package/dist/esm/commands/index.d.ts +1 -0
  24. package/dist/esm/commands/index.d.ts.map +1 -1
  25. package/dist/esm/commands/index.js +2 -0
  26. package/dist/esm/commands/index.js.map +1 -1
  27. package/dist/esm/queries/index.d.ts +1 -0
  28. package/dist/esm/queries/index.d.ts.map +1 -1
  29. package/dist/esm/queries/index.js +2 -0
  30. package/dist/esm/queries/index.js.map +1 -1
  31. package/dist/esm/reflection/PropertyDescriptor.d.ts +2 -1
  32. package/dist/esm/reflection/PropertyDescriptor.d.ts.map +1 -1
  33. package/dist/esm/reflection/PropertyDescriptor.js +3 -1
  34. package/dist/esm/reflection/PropertyDescriptor.js.map +1 -1
  35. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +2 -2
  37. package/queries/index.ts +1 -0
  38. package/reflection/PropertyDescriptor.ts +2 -1
@@ -32,7 +32,6 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
32
32
  /* eslint-enable @typescript-eslint/no-explicit-any */
33
33
  abstract readonly propertyDescriptors: PropertyDescriptor[];
34
34
  abstract get requestParameters(): string[];
35
- abstract get properties(): string[];
36
35
 
37
36
  private _initialValues: object = {};
38
37
  private _hasChanges = false;
@@ -113,7 +112,8 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
113
112
 
114
113
  private buildPayload(): object {
115
114
  const payload = {};
116
- this.properties.forEach(property => {
115
+ this.propertyDescriptors.forEach(propertyDescriptor => {
116
+ const property = propertyDescriptor.name;
117
117
  payload[property] = this[property];
118
118
  });
119
119
  return payload;
@@ -121,15 +121,17 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
121
121
 
122
122
  private validateRequiredProperties(): ValidationResult[] {
123
123
  const validationErrors: ValidationResult[] = [];
124
- this.properties.forEach(property => {
125
- const value = this[property];
126
- if (value === undefined || value === null || value === '') {
127
- validationErrors.push(new ValidationResult(
128
- ValidationResultSeverity.Error,
129
- `${property} is required`,
130
- [property],
131
- null
132
- ));
124
+ this.propertyDescriptors.forEach(propertyDescriptor => {
125
+ if (!propertyDescriptor.isOptional) {
126
+ const value = this[propertyDescriptor.name];
127
+ if (value === undefined || value === null || value === '') {
128
+ validationErrors.push(new ValidationResult(
129
+ ValidationResultSeverity.Error,
130
+ `${propertyDescriptor.name} is required`,
131
+ [propertyDescriptor.name],
132
+ null
133
+ ));
134
+ }
133
135
  }
134
136
  });
135
137
  return validationErrors;
@@ -180,7 +182,8 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
180
182
 
181
183
  /** @inheritdoc */
182
184
  clear(): void {
183
- this.properties.forEach(property => {
185
+ this.propertyDescriptors.forEach(propertyDescriptor => {
186
+ const property = propertyDescriptor.name;
184
187
  this[property] = undefined;
185
188
  });
186
189
  this._initialValues = {};
@@ -189,7 +192,8 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
189
192
 
190
193
  /** @inheritdoc */
191
194
  setInitialValues(values: TCommandContent) {
192
- this.properties.forEach(property => {
195
+ this.propertyDescriptors.forEach(propertyDescriptor => {
196
+ const property = propertyDescriptor.name;
193
197
  if (Object.prototype.hasOwnProperty.call(values, property)) {
194
198
  this._initialValues[property] = values[property];
195
199
  this[property] = values[property];
@@ -200,7 +204,8 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
200
204
 
201
205
  /** @inheritdoc */
202
206
  setInitialValuesFromCurrentValues() {
203
- this.properties.forEach(property => {
207
+ this.propertyDescriptors.forEach(propertyDescriptor => {
208
+ const property = propertyDescriptor.name;
204
209
  if (this[property]) {
205
210
  this._initialValues[property] = this[property];
206
211
  }
@@ -210,7 +215,8 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
210
215
 
211
216
  /** @inheritdoc */
212
217
  revertChanges(): void {
213
- this.properties.forEach(property => {
218
+ this.propertyDescriptors.forEach(propertyDescriptor => {
219
+ const property = propertyDescriptor.name;
214
220
  this[property] = this._initialValues[property];
215
221
  });
216
222
  }
@@ -244,6 +250,9 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
244
250
  }
245
251
 
246
252
  private updateHasChanges() {
247
- this._hasChanges = this.properties.some(property => this[property] !== this._initialValues[property]);
253
+ this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {
254
+ const property = propertyDescriptor.name;
255
+ return this[property] !== this._initialValues[property];
256
+ });
248
257
  }
249
258
  }
package/commands/index.ts CHANGED
@@ -7,3 +7,4 @@ export * from './ICommandResult';
7
7
  export * from './CommandResult';
8
8
  export * from './CommandResults';
9
9
  export * from './CommandValidator';
10
+ import '../validation';
@@ -15,7 +15,6 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
15
15
  readonly validation?: CommandValidator<any>;
16
16
  abstract readonly propertyDescriptors: PropertyDescriptor[];
17
17
  abstract get requestParameters(): string[];
18
- abstract get properties(): string[];
19
18
  private _initialValues;
20
19
  private _hasChanges;
21
20
  private _callbacks;
@@ -1 +1 @@
1
- {"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAYtE,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAsBzH,QAAQ,CAAC,aAAa,EAAE,WAAW;IAAW,QAAQ,CAAC,yBAAyB,EAAE,OAAO;IArBrG,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,oBAAoB,CAAiB;IAC7C,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC5D,QAAQ,KAAK,iBAAiB,IAAI,MAAM,EAAE,CAAC;IAC3C,QAAQ,KAAK,UAAU,IAAI,MAAM,EAAE,CAAC;IAEpC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,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AAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
@@ -72,17 +72,20 @@ class Command {
72
72
  }
73
73
  buildPayload() {
74
74
  const payload = {};
75
- this.properties.forEach(property => {
75
+ this.propertyDescriptors.forEach(propertyDescriptor => {
76
+ const property = propertyDescriptor.name;
76
77
  payload[property] = this[property];
77
78
  });
78
79
  return payload;
79
80
  }
80
81
  validateRequiredProperties() {
81
82
  const validationErrors = [];
82
- this.properties.forEach(property => {
83
- const value = this[property];
84
- if (value === undefined || value === null || value === '') {
85
- validationErrors.push(new ValidationResult.ValidationResult(ValidationResultSeverity.ValidationResultSeverity.Error, `${property} is required`, [property], null));
83
+ this.propertyDescriptors.forEach(propertyDescriptor => {
84
+ if (!propertyDescriptor.isOptional) {
85
+ const value = this[propertyDescriptor.name];
86
+ if (value === undefined || value === null || value === '') {
87
+ validationErrors.push(new ValidationResult.ValidationResult(ValidationResultSeverity.ValidationResultSeverity.Error, `${propertyDescriptor.name} is required`, [propertyDescriptor.name], null));
88
+ }
86
89
  }
87
90
  });
88
91
  return validationErrors;
@@ -121,14 +124,16 @@ class Command {
121
124
  }
122
125
  }
123
126
  clear() {
124
- this.properties.forEach(property => {
127
+ this.propertyDescriptors.forEach(propertyDescriptor => {
128
+ const property = propertyDescriptor.name;
125
129
  this[property] = undefined;
126
130
  });
127
131
  this._initialValues = {};
128
132
  this._hasChanges = false;
129
133
  }
130
134
  setInitialValues(values) {
131
- this.properties.forEach(property => {
135
+ this.propertyDescriptors.forEach(propertyDescriptor => {
136
+ const property = propertyDescriptor.name;
132
137
  if (Object.prototype.hasOwnProperty.call(values, property)) {
133
138
  this._initialValues[property] = values[property];
134
139
  this[property] = values[property];
@@ -137,7 +142,8 @@ class Command {
137
142
  this.updateHasChanges();
138
143
  }
139
144
  setInitialValuesFromCurrentValues() {
140
- this.properties.forEach(property => {
145
+ this.propertyDescriptors.forEach(propertyDescriptor => {
146
+ const property = propertyDescriptor.name;
141
147
  if (this[property]) {
142
148
  this._initialValues[property] = this[property];
143
149
  }
@@ -145,7 +151,8 @@ class Command {
145
151
  this.updateHasChanges();
146
152
  }
147
153
  revertChanges() {
148
- this.properties.forEach(property => {
154
+ this.propertyDescriptors.forEach(propertyDescriptor => {
155
+ const property = propertyDescriptor.name;
149
156
  this[property] = this._initialValues[property];
150
157
  });
151
158
  }
@@ -172,7 +179,10 @@ class Command {
172
179
  });
173
180
  }
174
181
  updateHasChanges() {
175
- this._hasChanges = this.properties.some(property => this[property] !== this._initialValues[property]);
182
+ this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {
183
+ const property = propertyDescriptor.name;
184
+ return this[property] !== this._initialValues[property];
185
+ });
176
186
  }
177
187
  }
178
188
 
@@ -1 +1 @@
1
- {"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n abstract get properties(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\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 async execute(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = `${this.route}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.properties.forEach(property => {\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.properties.forEach(property => {\n const value = this[property];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${property} is required`,\n [property],\n null\n ));\n }\n });\n return validationErrors;\n }\n\n private buildHeaders(): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.properties.forEach(property => {\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.properties.forEach(property => {\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.properties.forEach(property => {\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.properties.forEach(property => {\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.properties.some(property => this[property] !== this._initialValues[property]);\n }\n}\n"],"names":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAsBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AArB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAMX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;Q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Q,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACzG;AACH;;;;"}
1
+ {"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\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 async execute(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = `${this.route}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private buildHeaders(): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,E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AiB,CAAC,OAAO,CAAC,KAAK,EAAE;AACjD,YAAA,IAAI,QAAQ,IAAI,OAAO,EAAE;AACrB,gBAAA,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;YACpC;iBAAO;gBACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,iBAAiB,CAAC,QAAQ,CAAC;YAC5F;AACJ,QAAA,CAAC,CAAC;IACN;IAGA,iBAAiB,CAAC,QAAyB,EAAE,OAAe,EAAA;AACxD,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;AACjB,YAAA,QAAQ,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,IAAG;AAClE,YAAA,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI;YACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;AACH;;;;"}
@@ -4,4 +4,5 @@ export * from './ICommandResult';
4
4
  export * from './CommandResult';
5
5
  export * from './CommandResults';
6
6
  export * from './CommandValidator';
7
+ import '../validation';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../commands/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../commands/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,OAAO,eAAe,CAAC"}
@@ -4,6 +4,8 @@ var Command = require('./Command.js');
4
4
  var CommandResult = require('./CommandResult.js');
5
5
  var CommandResults = require('./CommandResults.js');
6
6
  var CommandValidator = require('./CommandValidator.js');
7
+ require('../validation/ValidationResultSeverity.js');
8
+ require('../validation/RuleBuilderExtensions.js');
7
9
 
8
10
 
9
11
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -18,4 +18,5 @@ export * from './WebSocketMessage';
18
18
  export * from './IQueryProvider';
19
19
  export * from './QueryProvider';
20
20
  export * from './QueryValidator';
21
+ import '../validation';
21
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../queries/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../queries/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,OAAO,eAAe,CAAC"}
@@ -16,6 +16,8 @@ var WebSocketMessage = require('./WebSocketMessage.js');
16
16
  var IQueryProvider = require('./IQueryProvider.js');
17
17
  var QueryProvider = require('./QueryProvider.js');
18
18
  var QueryValidator = require('./QueryValidator.js');
19
+ require('../validation/ValidationResultSeverity.js');
20
+ require('../validation/RuleBuilderExtensions.js');
19
21
 
20
22
 
21
23
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,6 +2,7 @@ import { Constructor } from '@cratis/fundamentals';
2
2
  export declare class PropertyDescriptor {
3
3
  readonly name: string;
4
4
  readonly type: Constructor;
5
- constructor(name: string, type: Constructor);
5
+ readonly isOptional: boolean;
6
+ constructor(name: string, type: Constructor, isOptional?: boolean);
6
7
  }
7
8
  //# sourceMappingURL=PropertyDescriptor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyDescriptor.d.ts","sourceRoot":"","sources":["../../../reflection/PropertyDescriptor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKnD,qBAAa,kBAAkB;IAMf,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW;gBAAxC,IAAI,EAAE,MAAM,EAAW,IAAI,EAAE,WAAW;CAEhE"}
1
+ {"version":3,"file":"PropertyDescriptor.d.ts","sourceRoot":"","sources":["../../../reflection/PropertyDescriptor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKnD,qBAAa,kBAAkB;IAOf,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO;gBAAtE,IAAI,EAAE,MAAM,EAAW,IAAI,EAAE,WAAW,EAAW,UAAU,GAAE,OAAe;CAEtG"}
@@ -3,9 +3,11 @@
3
3
  class PropertyDescriptor {
4
4
  name;
5
5
  type;
6
- constructor(name, type) {
6
+ isOptional;
7
+ constructor(name, type, isOptional = false) {
7
8
  this.name = name;
8
9
  this.type = type;
10
+ this.isOptional = isOptional;
9
11
  }
10
12
  }
11
13
 
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyDescriptor.js","sources":["../../../reflection/PropertyDescriptor.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 } from '@cratis/fundamentals';\n\n/**\n * Represents a property descriptor.\n */\nexport class PropertyDescriptor {\n /**\n * Initializes a new instance of the {@link PropertyDescriptor} class.\n * @param name Name of the property.\n * @param type Type of the property.\n */\n constructor(readonly name: string, readonly type: Constructor) {\n }\n}\n"],"names":[],"mappings":";;MAQa,kBAAkB,CAAA;AAMN,IAAA,IAAA;AAAuB,IAAA,IAAA;IAA5C,WAAA,CAAqB,IAAY,EAAW,IAAiB,EAAA;QAAxC,IAAA,CAAA,IAAI,GAAJ,IAAI;QAAmB,IAAA,CAAA,IAAI,GAAJ,IAAI;IAChD;AACH;;;;"}
1
+ {"version":3,"file":"PropertyDescriptor.js","sources":["../../../reflection/PropertyDescriptor.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 } from '@cratis/fundamentals';\n\n/**\n * Represents a property descriptor.\n */\nexport class PropertyDescriptor {\n /**\n * Initializes a new instance of the {@link PropertyDescriptor} class.\n * @param name Name of the property.\n * @param type Type of the property.\n * @param isOptional Whether the property is optional (nullable).\n */\n constructor(readonly name: string, readonly type: Constructor, readonly isOptional: boolean = false) {\n }\n}\n"],"names":[],"mappings":";;MAQa,kBAAkB,CAAA;AAON,IAAA,IAAA;AAAuB,IAAA,IAAA;AAA4B,IAAA,UAAA;AAAxE,IAAA,WAAA,CAAqB,IAAY,EAAW,IAAiB,EAAW,aAAsB,KAAK,EAAA;QAA9E,IAAA,CAAA,IAAI,GAAJ,IAAI;QAAmB,IAAA,CAAA,IAAI,GAAJ,IAAI;QAAwB,IAAA,CAAA,UAAU,GAAV,UAAU;IAClF;AACH;;;;"}
@@ -15,7 +15,6 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
15
15
  readonly validation?: CommandValidator<any>;
16
16
  abstract readonly propertyDescriptors: PropertyDescriptor[];
17
17
  abstract get requestParameters(): string[];
18
- abstract get properties(): string[];
19
18
  private _initialValues;
20
19
  private _hasChanges;
21
20
  private _callbacks;
@@ -1 +1 @@
1
- {"version":3,"file":"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= {};
73
- this.properties.forEach(property => {
73
+ this.propertyDescriptors.forEach(propertyDescriptor => {
74
+ const property = propertyDescriptor.name;
74
75
  payload[property] = this[property];
75
76
  });
76
77
  return payload;
77
78
  }
78
79
  validateRequiredProperties() {
79
80
  const validationErrors = [];
80
- this.properties.forEach(property => {
81
- const value = this[property];
82
- if (value === undefined || value === null || value === '') {
83
- validationErrors.push(new ValidationResult(ValidationResultSeverity.Error, `${property} is required`, [property], null));
81
+ this.propertyDescriptors.forEach(propertyDescriptor => {
82
+ if (!propertyDescriptor.isOptional) {
83
+ const value = this[propertyDescriptor.name];
84
+ if (value === undefined || value === null || value === '') {
85
+ validationErrors.push(new ValidationResult(ValidationResultSeverity.Error, `${propertyDescriptor.name} is required`, [propertyDescriptor.name], null));
86
+ }
84
87
  }
85
88
  });
86
89
  return validationErrors;
@@ -119,14 +122,16 @@ class Command {
119
122
  }
120
123
  }
121
124
  clear() {
122
- this.properties.forEach(property => {
125
+ this.propertyDescriptors.forEach(propertyDescriptor => {
126
+ const property = propertyDescriptor.name;
123
127
  this[property] = undefined;
124
128
  });
125
129
  this._initialValues = {};
126
130
  this._hasChanges = false;
127
131
  }
128
132
  setInitialValues(values) {
129
- this.properties.forEach(property => {
133
+ this.propertyDescriptors.forEach(propertyDescriptor => {
134
+ const property = propertyDescriptor.name;
130
135
  if (Object.prototype.hasOwnProperty.call(values, property)) {
131
136
  this._initialValues[property] = values[property];
132
137
  this[property] = values[property];
@@ -135,7 +140,8 @@ class Command {
135
140
  this.updateHasChanges();
136
141
  }
137
142
  setInitialValuesFromCurrentValues() {
138
- this.properties.forEach(property => {
143
+ this.propertyDescriptors.forEach(propertyDescriptor => {
144
+ const property = propertyDescriptor.name;
139
145
  if (this[property]) {
140
146
  this._initialValues[property] = this[property];
141
147
  }
@@ -143,7 +149,8 @@ class Command {
143
149
  this.updateHasChanges();
144
150
  }
145
151
  revertChanges() {
146
- this.properties.forEach(property => {
152
+ this.propertyDescriptors.forEach(propertyDescriptor => {
153
+ const property = propertyDescriptor.name;
147
154
  this[property] = this._initialValues[property];
148
155
  });
149
156
  }
@@ -170,7 +177,10 @@ class Command {
170
177
  });
171
178
  }
172
179
  updateHasChanges() {
173
- this._hasChanges = this.properties.some(property => this[property] !== this._initialValues[property]);
180
+ this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {
181
+ const property = propertyDescriptor.name;
182
+ return this[property] !== this._initialValues[property];
183
+ });
174
184
  }
175
185
  }
176
186
 
@@ -1 +1 @@
1
- {"version":3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n abstract get properties(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\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 async execute(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = `${this.route}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.properties.forEach(property => {\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.properties.forEach(property => {\n const value = this[property];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${property} is required`,\n [property],\n null\n ));\n }\n });\n return validationErrors;\n }\n\n private buildHeaders(): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.properties.forEach(property => {\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.properties.forEach(property => {\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.properties.forEach(property => {\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.properties.forEach(property => {\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.properties.some(property => this[property] !== this._initialValues[property]);\n }\n}\n"],"names":[],"mappings":";;;;;;;;MAuBsB,OAAO,CAAA;AAsBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AArB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAMX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;A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3,"file":"Command.js","sources":["../../../commands/Command.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 { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\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 async execute(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n const actualRoute = `${this.route}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private buildHeaders(): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\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 return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":[],"mappings":";;;;;;;;MAuBsB,OAAO,CAAA;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AA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C;AACjB,YAAA,QAAQ,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC;AAC/B,YAAA,OAAO,EAAE,IAAI,OAAO,CAAC,OAAO;AAC/B,SAAA,CAAC;IACN;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,IAAG;AAClE,YAAA,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI;YACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;AACH;;;;"}
@@ -4,4 +4,5 @@ export * from './ICommandResult';
4
4
  export * from './CommandResult';
5
5
  export * from './CommandResults';
6
6
  export * from './CommandValidator';
7
+ import '../validation';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../commands/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../commands/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,OAAO,eAAe,CAAC"}
@@ -2,4 +2,6 @@ export { Command } from './Command.js';
2
2
  export { CommandResult } from './CommandResult.js';
3
3
  export { CommandResults } from './CommandResults.js';
4
4
  export { CommandValidator } from './CommandValidator.js';
5
+ import '../validation/ValidationResultSeverity.js';
6
+ import '../validation/RuleBuilderExtensions.js';
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -18,4 +18,5 @@ export * from './WebSocketMessage';
18
18
  export * from './IQueryProvider';
19
19
  export * from './QueryProvider';
20
20
  export * from './QueryValidator';
21
+ import '../validation';
21
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../queries/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../queries/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,OAAO,eAAe,CAAC"}
@@ -14,4 +14,6 @@ export { WebSocketMessageType } from './WebSocketMessage.js';
14
14
  export { IQueryProvider } from './IQueryProvider.js';
15
15
  export { QueryProvider } from './QueryProvider.js';
16
16
  export { QueryValidator } from './QueryValidator.js';
17
+ import '../validation/ValidationResultSeverity.js';
18
+ import '../validation/RuleBuilderExtensions.js';
17
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -2,6 +2,7 @@ import { Constructor } from '@cratis/fundamentals';
2
2
  export declare class PropertyDescriptor {
3
3
  readonly name: string;
4
4
  readonly type: Constructor;
5
- constructor(name: string, type: Constructor);
5
+ readonly isOptional: boolean;
6
+ constructor(name: string, type: Constructor, isOptional?: boolean);
6
7
  }
7
8
  //# sourceMappingURL=PropertyDescriptor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyDescriptor.d.ts","sourceRoot":"","sources":["../../../reflection/PropertyDescriptor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKnD,qBAAa,kBAAkB;IAMf,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW;gBAAxC,IAAI,EAAE,MAAM,EAAW,IAAI,EAAE,WAAW;CAEhE"}
1
+ {"version":3,"file":"PropertyDescriptor.d.ts","sourceRoot":"","sources":["../../../reflection/PropertyDescriptor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKnD,qBAAa,kBAAkB;IAOf,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO;gBAAtE,IAAI,EAAE,MAAM,EAAW,IAAI,EAAE,WAAW,EAAW,UAAU,GAAE,OAAe;CAEtG"}