@cratis/arc 21.9.2 → 21.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/CommandResult.ts +5 -2
- package/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.ts +48 -0
- package/commands/for_CommandResult/when_creating_a_validation_failed_result.ts +25 -0
- package/dist/cjs/commands/CommandResult.js +4 -2
- package/dist/cjs/commands/CommandResult.js.map +1 -1
- package/dist/cjs/queries/QueryResult.js +4 -2
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/validation/ValidationResult.js +6 -1
- package/dist/cjs/validation/ValidationResult.js.map +1 -1
- package/dist/esm/commands/CommandResult.d.ts +1 -0
- package/dist/esm/commands/CommandResult.d.ts.map +1 -1
- package/dist/esm/commands/CommandResult.js +4 -2
- package/dist/esm/commands/CommandResult.js.map +1 -1
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts +2 -0
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts.map +1 -0
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.js +38 -0
- package/dist/esm/commands/for_CommandResult/when_constructing_from_a_server_result_with_a_constraint_violation.js.map +1 -0
- package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.d.ts +2 -0
- package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.d.ts.map +1 -0
- package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.js +12 -0
- package/dist/esm/commands/for_CommandResult/when_creating_a_validation_failed_result.js.map +1 -0
- package/dist/esm/queries/QueryResult.d.ts +1 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +4 -2
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts +2 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.js +28 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.js.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.d.ts +2 -0
- package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.js +12 -0
- package/dist/esm/queries/for_QueryResult/when_creating_a_validation_failed_result.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validation/ValidationResult.d.ts +2 -1
- package/dist/esm/validation/ValidationResult.d.ts.map +1 -1
- package/dist/esm/validation/ValidationResult.js +6 -1
- package/dist/esm/validation/ValidationResult.js.map +1 -1
- package/package.json +1 -1
- package/queries/QueryResult.ts +5 -2
- package/queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.ts +35 -0
- package/queries/for_QueryResult/when_creating_a_validation_failed_result.ts +27 -0
- package/validation/ValidationResult.ts +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\nimport { ChangeSet } from './ChangeSet';\nimport { deserializeQueryModel, deserializeQueryModels } from './deserializeQueryModel';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n changeSet?: ServerChangeSet;\n}\n\ntype ServerChangeSet = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n added: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replaced: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n removed: any[];\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n reason?: string;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n /**\n * Creates a {@link QueryResult} representing a query rejected by client-side validation, mirroring\n * {@link CommandResult.validationFailed} so a caller reads a failed query the same way it reads a failed command.\n * @param {ValidationResult[]} validationResults The validation results that caused the failure.\n * @param {object} query The query being rejected, which describes how to shape its own result.\n * @returns {QueryResult<TDataType>} A result that is neither successful nor valid.\n */\n static validationFailed<TDataType>(\n validationResults: ValidationResult[],\n query: { readonly defaultValue: TDataType; readonly modelType: Constructor; readonly enumerable: boolean }): QueryResult<TDataType> {\n const { defaultValue, modelType, enumerable } = query;\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, modelType, enumerable) as QueryResult<TDataType>;\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n this.data = (enumerable\n ? deserializeQueryModels(instanceType, result.data)\n : deserializeQueryModel(instanceType, result.data)) as TDataType;\n } else {\n this.data = (enumerable ? [] : null) as TDataType;\n }\n\n if (enumerable && result.changeSet) {\n this.changeSet = {\n added: deserializeQueryModels(instanceType, result.changeSet.added ?? []),\n replaced: deserializeQueryModels(instanceType, result.changeSet.replaced ?? []),\n removed: deserializeQueryModels(instanceType, result.changeSet.removed ?? []),\n } as ChangeSet<unknown>;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /**\n * Gets the optional change set describing what changed since the previous update.\n * Set by the server when the delta transfer mode is active.\n * When present, clients can apply the delta to their local state rather than replacing\n * the full dataset.\n */\n readonly changeSet?: ChangeSet<unknown>;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["QueryResult","empty","defaultValue","data","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","paging","totalItems","totalPages","page","size","Object","validationFailed","query","modelType","enumerable","map","_","severity","message","members","state","unauthorized","noSuccess","result","instanceType","ValidationResult","reason","PagingInfo","deserializeQueryModels","deserializeQueryModel","changeSet","added","replaced","removed","hasData","Array","isArray","length"],"mappings":";;;;AAAA;AACA;AAgDA;;;AAGC,IACM,MAAMA,WAAAA,CAAAA;IAET,OAAOC,KAAAA,CAAiBC,YAAuB,EAA0B;AACrE,QAAA,OAAO,IAAIF,WAAAA,CAAY;YACnBG,IAAAA,EAAMD,YAAAA;YACNE,SAAAA,EAAW,IAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,KAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;AACrBC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,mBAAAA,EAAqB,EAAA;YACrBC,MAAAA,EAAQ;g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AO,IAAI,EAAE;AAChF,aAAA;AACJ,QAAA;AACJ,IAAA;uBAGA,IAASpC;uBAGT,MAASQ;uBAGT,SAASP;uBAGT,YAASC;uBAGT,OAASC;uBAGT,aAASC;uBAGT,iBAASC;uBAGT,iBAASC;uBAGT,mBAASC;AAET;;;;;AAKC,QACD,SAAS0B;AAET;;AAEC,QACD,IAAII,OAAAA,GAAmB;QACnB,IAAI,IAAI,CAACrC,IAAI,EAAE;AACX,YAAA,IAAIsC,MAAMC,OAAO,CAAC,IAAI,CAACvC,IAAI,CAAA,EAAG;AAC1B,gBAAA,OAAO,IAAI,CAACA,IAAI,CAACwC,MAAM,GAAG,CAAA;AAC9B,YAAA;YACA,OAAO,IAAA;AACX,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"QueryResult.js","sources":["../../../queries/QueryResult.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { IQueryResult } from './IQueryResult';\nimport { PagingInfo } from './PagingInfo';\nimport { ChangeSet } from './ChangeSet';\nimport { deserializeQueryModel, deserializeQueryModels } from './deserializeQueryModel';\n\ntype ServerQueryResult = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n data: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: ServerValidationResult[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n paging: ServerPagingInfo;\n changeSet?: ServerChangeSet;\n}\n\ntype ServerChangeSet = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n added: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replaced: any[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n removed: any[];\n}\n\ntype ServerValidationResult = {\n severity: number;\n message: string;\n members: string[];\n state: object;\n reason?: string;\n reasonDetail?: string;\n}\n\ntype ServerPagingInfo = {\n page: number;\n size: number; \n totalItems: number;\n totalPages: number;\n}\n\n/**\n * Represents the result from executing a {@link IQueryFor}.\n * @template TDataType The data type.\n */\nexport class QueryResult<TDataType = object> implements IQueryResult<TDataType> {\n\n static empty<TDataType>(defaultValue: TDataType): QueryResult<TDataType> {\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n\n }, Object, false);\n }\n\n /**\n * Creates a {@link QueryResult} representing a query rejected by client-side validation, mirroring\n * {@link CommandResult.validationFailed} so a caller reads a failed query the same way it reads a failed command.\n * @param {ValidationResult[]} validationResults The validation results that caused the failure.\n * @param {object} query The query being rejected, which describes how to shape its own result.\n * @returns {QueryResult<TDataType>} A result that is neither successful nor valid.\n */\n static validationFailed<TDataType>(\n validationResults: ValidationResult[],\n query: { readonly defaultValue: TDataType; readonly modelType: Constructor; readonly enumerable: boolean }): QueryResult<TDataType> {\n const { defaultValue, modelType, enumerable } = query;\n return new QueryResult({\n data: defaultValue as object,\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state,\n reason: _.reason,\n reasonDetail: _.reasonDetail\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, modelType, enumerable) as QueryResult<TDataType>;\n }\n\n static unauthorized<TDataType>(): QueryResult<TDataType> {\n return new QueryResult({\n data: null as unknown as object,\n isSuccess: false,\n isAuthorized: false,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n }\n\n static noSuccess: QueryResult = new QueryResult({\n data: {},\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n paging: {\n totalItems: 0,\n totalPages: 0,\n page: 0,\n size: 0\n }\n }, Object, false);\n\n /**\n * Creates an instance of query result.\n * @param {*} result The raw result from the backend.\n * @param {Constructor} instanceType The type of instance to deserialize.\n * @param {boolean} enumerable Whether or not the result is supposed be an enumerable or not.\n */\n constructor(result: ServerQueryResult, instanceType: Constructor, enumerable: boolean) {\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.paging = new PagingInfo();\n this.paging.page = result.paging.page;\n this.paging.size = result.paging.size;\n this.paging.totalItems = result.paging.totalItems;\n this.paging.totalPages = result.paging.totalPages;\n\n if (result.data) {\n this.data = (enumerable\n ? deserializeQueryModels(instanceType, result.data)\n : deserializeQueryModel(instanceType, result.data)) as TDataType;\n } else {\n this.data = (enumerable ? [] : null) as TDataType;\n }\n\n if (enumerable && result.changeSet) {\n this.changeSet = {\n added: deserializeQueryModels(instanceType, result.changeSet.added ?? []),\n replaced: deserializeQueryModels(instanceType, result.changeSet.replaced ?? []),\n removed: deserializeQueryModels(instanceType, result.changeSet.removed ?? []),\n } as ChangeSet<unknown>;\n }\n }\n\n /** @inheritdoc */\n readonly data: TDataType;\n\n /** @inheritdoc */\n readonly paging: PagingInfo;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /**\n * Gets the optional change set describing what changed since the previous update.\n * Set by the server when the delta transfer mode is active.\n * When present, clients can apply the delta to their local state rather than replacing\n * the full dataset.\n */\n readonly changeSet?: ChangeSet<unknown>;\n\n /**\n * Gets whether or not the query has data.\n */\n get hasData(): boolean {\n if (this.data) {\n if (Array.isArray(this.data)) {\n return this.data.length > 0;\n }\n return true;\n }\n return false;\n }\n}\n"],"names":["QueryResult","empty","defaultValue","data","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","paging","totalItems","totalPages","page","size","Object","validationFailed","query","modelType","enumerable","map","_","severity","message","members","state","reason","reasonDetail","unauthorized","noSuccess","result","instanceType","ValidationResult","PagingInfo","deserializeQueryModels","deserializeQueryModel","changeSet","added","replaced","removed","hasData","Array","isArray","length"],"mappings":";;;;AAAA;AACA;AAiDA;;;AAGC,IACM,MAAMA,WAAAA,CAAAA;IAET,OAAOC,KAAAA,CAAiBC,YAAuB,EAA0B;AACrE,QAAA,OAAO,IAAIF,WAAAA,CAAY;YACnBG,IAAAA,EAAMD,YAAAA;YACNE,SAAAA,EAAW,IAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,KAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;AACrBC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,mBAAAA,EAAqB,EAAA;YACrBC,MAAAA,EAAQ;gBACJC,UAAAA,EAAY,CAAA;gBACZC,UAAAA,EAAY,CAAA;gBACZC,IAAAA,EAAM,CAAA;gBACNC,IAAAA,EAAM;AACV;AAEJ,SAAA,EAAGC,MAAAA,EAAQ,KAAA,CAAA;AACf,IAAA;AAEA;;;;;;AAMC,QACD,OAAOC,gBAAAA,CACHT,iBAA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BAGT,SAASP;uBAGT,YAASC;uBAGT,OAASC;uBAGT,aAASC;uBAGT,iBAASC;uBAGT,iBAASC;uBAGT,mBAASC;AAET;;;;;AAKC,QACD,SAAS2B;AAET;;AAEC,QACD,IAAII,OAAAA,GAAmB;QACnB,IAAI,IAAI,CAACtC,IAAI,EAAE;AACX,YAAA,IAAIuC,MAAMC,OAAO,CAAC,IAAI,CAACxC,IAAI,CAAA,EAAG;AAC1B,gBAAA,OAAO,IAAI,CAACA,IAAI,CAACyC,MAAM,GAAG,CAAA;AAC9B,YAAA;YACA,OAAO,IAAA;AACX,QAAA;QACA,OAAO,KAAA;AACX,IAAA;AACJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_constructing_from_a_server_result_with_a_constraint_violation.d.ts","sourceRoot":"","sources":["../../../../queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ValidationResultReason } from '../../validation/ValidationResultReason';
|
|
2
|
+
import { ValidationResultSeverity } from '../../validation/ValidationResultSeverity';
|
|
3
|
+
import { QueryResult } from '../QueryResult';
|
|
4
|
+
describe('when constructing from a server result with a constraint violation', () => {
|
|
5
|
+
const result = new QueryResult({
|
|
6
|
+
data: {},
|
|
7
|
+
isSuccess: false,
|
|
8
|
+
isAuthorized: true,
|
|
9
|
+
isValid: false,
|
|
10
|
+
hasExceptions: false,
|
|
11
|
+
validationResults: [
|
|
12
|
+
{
|
|
13
|
+
severity: ValidationResultSeverity.Error,
|
|
14
|
+
message: 'The organization number is already in use',
|
|
15
|
+
members: ['organizationNumber'],
|
|
16
|
+
state: {},
|
|
17
|
+
reason: ValidationResultReason.ConstraintViolation,
|
|
18
|
+
reasonDetail: 'UniqueOrganizationNumber'
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
exceptionMessages: [],
|
|
22
|
+
exceptionStackTrace: '',
|
|
23
|
+
paging: { page: 0, size: 0, totalItems: 0, totalPages: 0 }
|
|
24
|
+
}, Object, false);
|
|
25
|
+
it('should carry what kind of thing rejected the query', () => result.validationResults[0].reason.should.equal(ValidationResultReason.ConstraintViolation));
|
|
26
|
+
it('should carry the name of the violated constraint', () => result.validationResults[0].reasonDetail.should.equal('UniqueOrganizationNumber'));
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=when_constructing_from_a_server_result_with_a_constraint_violation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_constructing_from_a_server_result_with_a_constraint_violation.js","sourceRoot":"","sources":["../../../../queries/for_QueryResult/when_constructing_from_a_server_result_with_a_constraint_violation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,QAAQ,CAAC,oEAAoE,EAAE,GAAG,EAAE;IAChF,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC;QAC3B,IAAI,EAAE,EAAE;QACR,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,KAAK;QACd,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE;YACf;gBACI,QAAQ,EAAE,wBAAwB,CAAC,KAAK;gBACxC,OAAO,EAAE,2CAA2C;gBACpD,OAAO,EAAE,CAAC,oBAAoB,CAAC;gBAC/B,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,sBAAsB,CAAC,mBAAmB;gBAClD,YAAY,EAAE,0BAA0B;aAC3C;SACJ;QACD,iBAAiB,EAAE,EAAE;QACrB,mBAAmB,EAAE,EAAE;QACvB,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;KAC7D,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAElB,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE,CAC1D,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAEjG,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE,CACxD,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,YAAa,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_creating_a_validation_failed_result.d.ts","sourceRoot":"","sources":["../../../../queries/for_QueryResult/when_creating_a_validation_failed_result.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidationResult } from '../../validation/ValidationResult';
|
|
2
|
+
import { ValidationResultReason } from '../../validation/ValidationResultReason';
|
|
3
|
+
import { ValidationResultSeverity } from '../../validation/ValidationResultSeverity';
|
|
4
|
+
import { QueryResult } from '../QueryResult';
|
|
5
|
+
describe('when creating a validation failed result', () => {
|
|
6
|
+
const result = QueryResult.validationFailed([
|
|
7
|
+
new ValidationResult(ValidationResultSeverity.Error, 'The organization number is already in use', ['organizationNumber'], {}, ValidationResultReason.ConstraintViolation, 'UniqueOrganizationNumber')
|
|
8
|
+
], { defaultValue: {}, modelType: Object, enumerable: false });
|
|
9
|
+
it('should keep the reason the caller gave it', () => result.validationResults[0].reason.should.equal(ValidationResultReason.ConstraintViolation));
|
|
10
|
+
it('should keep the name of the violated constraint', () => result.validationResults[0].reasonDetail.should.equal('UniqueOrganizationNumber'));
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=when_creating_a_validation_failed_result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_creating_a_validation_failed_result.js","sourceRoot":"","sources":["../../../../queries/for_QueryResult/when_creating_a_validation_failed_result.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACtD,MAAM,MAAM,GAAG,WAAW,CAAC,gBAAgB,CAAC;QACxC,IAAI,gBAAgB,CAChB,wBAAwB,CAAC,KAAK,EAC9B,2CAA2C,EAC3C,CAAC,oBAAoB,CAAC,EACtB,EAAE,EACF,sBAAsB,CAAC,mBAAmB,EAC1C,0BAA0B,CAAC;KAClC,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/D,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE,CACjD,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAEjG,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE,CACvD,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,YAAa,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC,CAAC"}
|