@bessemer/cornerstone 0.5.96 → 0.5.97
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.
@@ -65,11 +65,12 @@ export declare const unhandled: (builder?: ErrorEventAugment) => ErrorEvent;
|
|
65
65
|
export declare const required: (builder?: ErrorEventAugment) => ErrorEvent;
|
66
66
|
export declare const unauthorized: (builder?: ErrorEventAugment) => ErrorEvent;
|
67
67
|
export declare const forbidden: (builder?: ErrorEventAugment) => ErrorEvent;
|
68
|
+
export declare const badRequest: (builder?: ErrorEventAugment) => ErrorEvent;
|
68
69
|
export declare const invalidValue: (value: unknown, builder?: ErrorEventAugment) => ErrorEvent;
|
69
70
|
export declare function assertPresent<T>(value: T, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is NonNullable<T>;
|
70
71
|
export declare function assertAuthorized(value: boolean, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is true;
|
71
72
|
export declare function assertPermitted(value: boolean, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is true;
|
72
|
-
export declare function assertValid(
|
73
|
+
export declare function assertValid(value: boolean, builder?: LazyValue<ErrorEventAugment | undefined>): asserts value is true;
|
73
74
|
export declare function assert(value: boolean, builder: LazyValue<ErrorEventBuilder>): asserts value is true;
|
74
75
|
export declare const unpackResult: <T>(result: Result<T, ErrorEvent>) => T;
|
75
76
|
//# sourceMappingURL=error-event.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../../src/error/error-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAyC,eAAe,EAAE,MAAM,8BAA8B,CAAA;AACrG,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAY,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAGhE,OAAO,EAAkC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AAY,GAAI,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,KAAG,CAM/D,CAAA"}
|
@@ -156,6 +156,16 @@ var forbidden = (builder) => of(
|
|
156
156
|
builder
|
157
157
|
)
|
158
158
|
);
|
159
|
+
var badRequest = (builder) => of(
|
160
|
+
deepMerge(
|
161
|
+
{
|
162
|
+
type: InvalidValue,
|
163
|
+
message: "The format is invalid and cannot be processed.",
|
164
|
+
attributes: { [HttpStatusCodeAttribute]: 400 }
|
165
|
+
},
|
166
|
+
builder
|
167
|
+
)
|
168
|
+
);
|
159
169
|
var invalidValue = (value, builder) => of(
|
160
170
|
deepMerge(
|
161
171
|
{
|
@@ -181,9 +191,9 @@ function assertPermitted(value, builder = () => void 0) {
|
|
181
191
|
throw new ErrorEventException(forbidden(evaluate(builder)));
|
182
192
|
}
|
183
193
|
}
|
184
|
-
function assertValid(
|
185
|
-
if (!
|
186
|
-
throw new ErrorEventException(
|
194
|
+
function assertValid(value, builder = () => void 0) {
|
195
|
+
if (!value) {
|
196
|
+
throw new ErrorEventException(badRequest(evaluate(builder)));
|
187
197
|
}
|
188
198
|
}
|
189
199
|
function assert(value, builder) {
|
@@ -211,6 +221,7 @@ export {
|
|
211
221
|
assertPermitted,
|
212
222
|
assertPresent,
|
213
223
|
assertValid,
|
224
|
+
badRequest,
|
214
225
|
buildErrorCode,
|
215
226
|
forbidden,
|
216
227
|
from,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/error/error-event.ts"],"sourcesContent":["import { Dictionary, Throwable } from '@bessemer/cornerstone/types'\nimport { deepMerge, isNil, isObject, isPresent, RecordAttribute } from '@bessemer/cornerstone/object'\nimport Zod, { ZodType } from 'zod'\nimport { evaluate, LazyValue } from '@bessemer/cornerstone/lazy'\nimport { findInCausalChain as errorsFindInCausalChain, isError } from '@bessemer/cornerstone/error/error'\nimport { isPromise } from '@bessemer/cornerstone/promise'\nimport { applyNamespace, emptyNamespace, NamespacedKey, ResourceNamespace, splitNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorType, Forbidden, InvalidValue, Required, Unauthorized, Unhandled } from '@bessemer/cornerstone/error/error-type'\nimport { Result } from '@bessemer/cornerstone/result'\n\n/*\n Represents a structured error event. The code can be mapped to a unique type of error while the\n message and attributes can provide contextual information about the error. Finally,\n an ErrorEvent could have multiple causes which get aggregated into a single parent error.\n */\nexport type ErrorCode = NamespacedKey<ErrorType>\nexport const ErrorCodeSchema = Zod.string().transform((it) => it as NamespacedKey<ErrorType>)\n\nexport const splitErrorCode = (code: ErrorCode): [ErrorType, ResourceNamespace] => {\n return splitNamespace(code)\n}\n\nexport const getErrorCodeType = (code: ErrorCode): ErrorType => {\n const [errorType] = splitErrorCode(code)\n return errorType\n}\n\nexport type ErrorCodeBuilder =\n | {\n code: ErrorCode\n }\n | { type: ErrorType; namespace?: ResourceNamespace }\n\nexport const buildErrorCode = (builder: ErrorCodeBuilder): ErrorCode => {\n if ('code' in builder) {\n return builder.code\n } else {\n return applyNamespace(builder.type, builder.namespace ?? emptyNamespace())\n }\n}\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ErrorAttributeSchema: ZodType<ErrorAttribute, string> = Zod.string()\n\nexport const ErrorEventCauseSchema = Zod.object({\n code: ErrorCodeSchema,\n message: Zod.string(),\n attributes: Zod.record(Zod.string(), Zod.unknown()),\n})\n\nexport type ErrorEventCause = Zod.infer<typeof ErrorEventCauseSchema>\n\nexport const Schema = Zod.object({\n message: Zod.string(),\n causes: Zod.array(ErrorEventCauseSchema),\n attributes: Zod.record(ErrorAttributeSchema, Zod.unknown()),\n})\n\nexport type ErrorEvent = Zod.infer<typeof Schema>\n\nexport type ErrorEventCauseBuilder = ErrorCodeBuilder & {\n message: string\n attributes?: Dictionary<unknown>\n}\n\nexport type ErrorEventBuilder = {\n attributes?: Record<ErrorAttribute, unknown>\n} & (\n | {\n causes: Array<ErrorEventCauseBuilder>\n message: string\n }\n | (ErrorCodeBuilder & {\n message: string\n })\n)\n\nexport type ErrorEventAugment = Partial<ErrorEventBuilder>\n\n// An exception type that contains an ErrorEvent\nexport class ErrorEventException extends Error {\n readonly errorEvent: ErrorEvent\n\n constructor(errorEvent: ErrorEvent, cause?: unknown) {\n super(errorEvent.message ?? '', { cause })\n this.name = this.constructor.name\n this.errorEvent = errorEvent\n }\n}\n\nexport const isErrorEvent = (throwable: Throwable): throwable is ErrorEvent => {\n if (!isObject(throwable)) {\n return false\n }\n\n const errorEvent = throwable as ErrorEvent\n return isPresent(errorEvent.message) && isPresent(errorEvent.attributes) && isPresent(errorEvent.causes)\n}\n\nexport const isErrorEventException = (throwable: Throwable): throwable is ErrorEventException => {\n return throwable instanceof ErrorEventException\n}\n\nexport const of = (builder: ErrorEventBuilder): ErrorEvent => {\n if ('causes' in builder) {\n return {\n causes: builder.causes.map((it) => {\n return {\n code: buildErrorCode(it),\n message: it.message,\n attributes: it.attributes ?? {},\n }\n }),\n message: builder.message,\n attributes: builder.attributes ?? {},\n }\n } else {\n return {\n causes: [\n {\n code: buildErrorCode(builder),\n message: builder.message,\n attributes: {},\n },\n ],\n message: builder.message,\n attributes: builder.attributes ?? {},\n }\n }\n}\n\nexport const from = (throwable: Throwable): ErrorEvent => {\n if (isErrorEvent(throwable)) {\n return throwable\n }\n\n if (!isError(throwable)) {\n return unhandled()\n }\n\n const errorEventException = errorsFindInCausalChain(throwable, isErrorEventException) as ErrorEventException | undefined\n if (isNil(errorEventException)) {\n return unhandled()\n }\n\n return errorEventException.errorEvent\n}\n\nexport function withPropagation<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType\nexport function withPropagation<ReturnType>(runnable: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>\nexport function withPropagation<ReturnType>(\n runnable: () => ReturnType | Promise<ReturnType>,\n attributes: LazyValue<Dictionary<unknown>>\n): ReturnType | Promise<ReturnType> {\n try {\n let result = runnable()\n if (isPromise(result)) {\n return result.then((it) => it).catch((it) => propagate(it, evaluate(attributes)))\n } else {\n return result\n }\n } catch (throwable: Throwable) {\n throw propagate(throwable, evaluate(attributes))\n }\n}\n\nexport const propagate = (throwable: Throwable, attributes: Dictionary<unknown>): never => {\n if (isErrorEventException(throwable)) {\n // We just mutate the existing error event to avoid nested exceptions\n const errorEvent = throwable.errorEvent\n errorEvent.attributes = { ...errorEvent.attributes, ...attributes }\n throw throwable\n } else {\n const errorEvent = from(throwable)\n const contextualizedEvent = of({ ...errorEvent, attributes: { ...errorEvent.attributes, ...attributes } })\n throw new ErrorEventException(contextualizedEvent, throwable)\n }\n}\n\nexport const ValueAttribute: ErrorAttribute = 'value'\nexport const RequestCorrelationIdAttribute: ErrorAttribute<string> = 'requestCorrelationId'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nexport const unhandled = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Unhandled,\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n },\n builder\n )\n )\n\nexport const required = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Required,\n message: 'The resource is required.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n },\n builder\n )\n )\n\nexport const unauthorized = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Unauthorized,\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n },\n builder\n )\n )\n\nexport const forbidden = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Forbidden,\n message: 'The requested Resource requires additional permissions to access.',\n attributes: { [HttpStatusCodeAttribute]: 403 },\n },\n builder\n )\n )\n\nexport const invalidValue = (value: unknown, builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: InvalidValue,\n message: 'The format is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400, [ValueAttribute]: value },\n },\n builder\n )\n )\n\nexport function assertPresent<T>(value: T, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is NonNullable<T> {\n if (isNil(value)) {\n throw new ErrorEventException(required(evaluate(builder)))\n }\n}\n\nexport function assertAuthorized(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(unauthorized(evaluate(builder)))\n }\n}\n\nexport function assertPermitted(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(forbidden(evaluate(builder)))\n }\n}\n\nexport function assertValid(\n valid: boolean,\n value: unknown,\n builder: LazyValue<ErrorEventAugment | undefined> = () => undefined\n): asserts value is true {\n if (!valid) {\n throw new ErrorEventException(invalidValue(value, evaluate(builder)))\n }\n}\n\nexport function assert(value: boolean, builder: LazyValue<ErrorEventBuilder>): asserts value is true {\n if (!value) {\n throw new ErrorEventException(of(evaluate(builder)))\n }\n}\n\nexport const unpackResult = <T>(result: Result<T, ErrorEvent>): T => {\n if (!result.isSuccess) {\n throw new ErrorEventException(result.value)\n }\n\n return result.value\n}\n"],"mappings":";AACA,SAAS,WAAW,OAAO,UAAU,iBAAkC;AACvE,OAAO,SAAsB;AAC7B,SAAS,gBAA2B;AACpC,SAAS,qBAAqB,yBAAyB,eAAe;AACtE,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,gBAAkD,sBAAsB;AACjG,SAAoB,WAAW,cAAc,UAAU,cAAc,iBAAiB;AAS/E,IAAM,kBAAkB,IAAI,OAAO,EAAE,UAAU,CAAC,OAAO,EAA8B;AAErF,IAAM,iBAAiB,CAAC,SAAoD;AACjF,SAAO,eAAe,IAAI;AAC5B;AAEO,IAAM,mBAAmB,CAAC,SAA+B;AAC9D,QAAM,CAAC,SAAS,IAAI,eAAe,IAAI;AACvC,SAAO;AACT;AAQO,IAAM,iBAAiB,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AACV,UAAM,IAAI,oBAAoB,aAAa,SAAS,OAAO,CAAC,CAAC;AAAA,EAC/D;AACF;AAEO,SAAS,gBAAgB,OAAgB,UAAoD,MAAM,QAAkC;AAC1I,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,oBAAoB,UAAU,SAAS,OAAO,CAAC,CAAC;AAAA,EAC5D;AACF;AAEO,SAAS,YACd,OACA,OACA,UAAoD,MAAM,QACnC;AACvB,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,oBAAoB,aAAa,OAAO,SAAS,OAAO,CAAC,CAAC;AAAA,EACtE;AACF;AAEO,SAAS,OAAO,OAAgB,SAA8D;AACnG,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,oBAAoB,GAAG,SAAS,OAAO,CAAC,CAAC;AAAA,EACrD;AACF;AAEO,IAAM,eAAe,CAAI,WAAqC;AACnE,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,IAAI,oBAAoB,OAAO,KAAK;AAAA,EAC5C;AAEA,SAAO,OAAO;AAChB;","names":[]}
|
1
|
+
{"version":3,"sources":["../../src/error/error-event.ts"],"sourcesContent":["import { Dictionary, Throwable } from '@bessemer/cornerstone/types'\nimport { deepMerge, isNil, isObject, isPresent, RecordAttribute } from '@bessemer/cornerstone/object'\nimport Zod, { ZodType } from 'zod'\nimport { evaluate, LazyValue } from '@bessemer/cornerstone/lazy'\nimport { findInCausalChain as errorsFindInCausalChain, isError } from '@bessemer/cornerstone/error/error'\nimport { isPromise } from '@bessemer/cornerstone/promise'\nimport { applyNamespace, emptyNamespace, NamespacedKey, ResourceNamespace, splitNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorType, Forbidden, InvalidValue, Required, Unauthorized, Unhandled } from '@bessemer/cornerstone/error/error-type'\nimport { Result } from '@bessemer/cornerstone/result'\n\n/*\n Represents a structured error event. The code can be mapped to a unique type of error while the\n message and attributes can provide contextual information about the error. Finally,\n an ErrorEvent could have multiple causes which get aggregated into a single parent error.\n */\nexport type ErrorCode = NamespacedKey<ErrorType>\nexport const ErrorCodeSchema = Zod.string().transform((it) => it as NamespacedKey<ErrorType>)\n\nexport const splitErrorCode = (code: ErrorCode): [ErrorType, ResourceNamespace] => {\n return splitNamespace(code)\n}\n\nexport const getErrorCodeType = (code: ErrorCode): ErrorType => {\n const [errorType] = splitErrorCode(code)\n return errorType\n}\n\nexport type ErrorCodeBuilder =\n | {\n code: ErrorCode\n }\n | { type: ErrorType; namespace?: ResourceNamespace }\n\nexport const buildErrorCode = (builder: ErrorCodeBuilder): ErrorCode => {\n if ('code' in builder) {\n return builder.code\n } else {\n return applyNamespace(builder.type, builder.namespace ?? emptyNamespace())\n }\n}\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ErrorAttributeSchema: ZodType<ErrorAttribute, string> = Zod.string()\n\nexport const ErrorEventCauseSchema = Zod.object({\n code: ErrorCodeSchema,\n message: Zod.string(),\n attributes: Zod.record(Zod.string(), Zod.unknown()),\n})\n\nexport type ErrorEventCause = Zod.infer<typeof ErrorEventCauseSchema>\n\nexport const Schema = Zod.object({\n message: Zod.string(),\n causes: Zod.array(ErrorEventCauseSchema),\n attributes: Zod.record(ErrorAttributeSchema, Zod.unknown()),\n})\n\nexport type ErrorEvent = Zod.infer<typeof Schema>\n\nexport type ErrorEventCauseBuilder = ErrorCodeBuilder & {\n message: string\n attributes?: Dictionary<unknown>\n}\n\nexport type ErrorEventBuilder = {\n attributes?: Record<ErrorAttribute, unknown>\n} & (\n | {\n causes: Array<ErrorEventCauseBuilder>\n message: string\n }\n | (ErrorCodeBuilder & {\n message: string\n })\n)\n\nexport type ErrorEventAugment = Partial<ErrorEventBuilder>\n\n// An exception type that contains an ErrorEvent\nexport class ErrorEventException extends Error {\n readonly errorEvent: ErrorEvent\n\n constructor(errorEvent: ErrorEvent, cause?: unknown) {\n super(errorEvent.message ?? '', { cause })\n this.name = this.constructor.name\n this.errorEvent = errorEvent\n }\n}\n\nexport const isErrorEvent = (throwable: Throwable): throwable is ErrorEvent => {\n if (!isObject(throwable)) {\n return false\n }\n\n const errorEvent = throwable as ErrorEvent\n return isPresent(errorEvent.message) && isPresent(errorEvent.attributes) && isPresent(errorEvent.causes)\n}\n\nexport const isErrorEventException = (throwable: Throwable): throwable is ErrorEventException => {\n return throwable instanceof ErrorEventException\n}\n\nexport const of = (builder: ErrorEventBuilder): ErrorEvent => {\n if ('causes' in builder) {\n return {\n causes: builder.causes.map((it) => {\n return {\n code: buildErrorCode(it),\n message: it.message,\n attributes: it.attributes ?? {},\n }\n }),\n message: builder.message,\n attributes: builder.attributes ?? {},\n }\n } else {\n return {\n causes: [\n {\n code: buildErrorCode(builder),\n message: builder.message,\n attributes: {},\n },\n ],\n message: builder.message,\n attributes: builder.attributes ?? {},\n }\n }\n}\n\nexport const from = (throwable: Throwable): ErrorEvent => {\n if (isErrorEvent(throwable)) {\n return throwable\n }\n\n if (!isError(throwable)) {\n return unhandled()\n }\n\n const errorEventException = errorsFindInCausalChain(throwable, isErrorEventException) as ErrorEventException | undefined\n if (isNil(errorEventException)) {\n return unhandled()\n }\n\n return errorEventException.errorEvent\n}\n\nexport function withPropagation<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType\nexport function withPropagation<ReturnType>(runnable: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>\nexport function withPropagation<ReturnType>(\n runnable: () => ReturnType | Promise<ReturnType>,\n attributes: LazyValue<Dictionary<unknown>>\n): ReturnType | Promise<ReturnType> {\n try {\n let result = runnable()\n if (isPromise(result)) {\n return result.then((it) => it).catch((it) => propagate(it, evaluate(attributes)))\n } else {\n return result\n }\n } catch (throwable: Throwable) {\n throw propagate(throwable, evaluate(attributes))\n }\n}\n\nexport const propagate = (throwable: Throwable, attributes: Dictionary<unknown>): never => {\n if (isErrorEventException(throwable)) {\n // We just mutate the existing error event to avoid nested exceptions\n const errorEvent = throwable.errorEvent\n errorEvent.attributes = { ...errorEvent.attributes, ...attributes }\n throw throwable\n } else {\n const errorEvent = from(throwable)\n const contextualizedEvent = of({ ...errorEvent, attributes: { ...errorEvent.attributes, ...attributes } })\n throw new ErrorEventException(contextualizedEvent, throwable)\n }\n}\n\nexport const ValueAttribute: ErrorAttribute = 'value'\nexport const RequestCorrelationIdAttribute: ErrorAttribute<string> = 'requestCorrelationId'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nexport const unhandled = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Unhandled,\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n },\n builder\n )\n )\n\nexport const required = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Required,\n message: 'The resource is required.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n },\n builder\n )\n )\n\nexport const unauthorized = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Unauthorized,\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n },\n builder\n )\n )\n\nexport const forbidden = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: Forbidden,\n message: 'The requested Resource requires additional permissions to access.',\n attributes: { [HttpStatusCodeAttribute]: 403 },\n },\n builder\n )\n )\n\nexport const badRequest = (builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: InvalidValue,\n message: 'The format is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400 },\n },\n builder\n )\n )\n\nexport const invalidValue = (value: unknown, builder?: ErrorEventAugment): ErrorEvent =>\n of(\n deepMerge(\n {\n type: InvalidValue,\n message: 'The format is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400, [ValueAttribute]: value },\n },\n builder\n )\n )\n\nexport function assertPresent<T>(value: T, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is NonNullable<T> {\n if (isNil(value)) {\n throw new ErrorEventException(required(evaluate(builder)))\n }\n}\n\nexport function assertAuthorized(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(unauthorized(evaluate(builder)))\n }\n}\n\nexport function assertPermitted(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(forbidden(evaluate(builder)))\n }\n}\n\nexport function assertValid(value: boolean, builder: LazyValue<ErrorEventAugment | undefined> = () => undefined): asserts value is true {\n if (!value) {\n throw new ErrorEventException(badRequest(evaluate(builder)))\n }\n}\n\nexport function assert(value: boolean, builder: LazyValue<ErrorEventBuilder>): asserts value is true {\n if (!value) {\n throw new ErrorEventException(of(evaluate(builder)))\n }\n}\n\nexport const unpackResult = <T>(result: Result<T, ErrorEvent>): T => {\n if (!result.isSuccess) {\n throw new ErrorEventException(result.value)\n }\n\n return result.value\n}\n"],"mappings":";AACA,SAAS,WAAW,OAAO,UAAU,iBAAkC;AACvE,OAAO,SAAsB;AAC7B,SAAS,gBAA2B;AACpC,SAAS,qBAAqB,yBAAyB,eAAe;AACtE,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,gBAAkD,sBAAsB;AACjG,SAAoB,WAAW,cAAc,UAAU,cAAc,iBAAiB;AAS/E,IAAM,kBAAkB,IAAI,OAAO,EAAE,UAAU,CAAC,OAAO,EAA8B;AAErF,IAAM,iBAAiB,CAAC,SAAoD;AACjF,SAAO,eAAe,IAAI;AAC5B;AAEO,IAAM,mBAAmB,CAAC,SAA+B;AAC9D,QAAM,CAAC,SAAS,IAAI,eAAe,IAAI;AACvC,SAAO;AACT;AAQO,IAAM,iBAAiB,CAAC,YAAyC;AACtE,MAAI,UAAU,SAAS;AACrB,WAAO,QAAQ;AAAA,EACjB,OAAO;AACL,WAAO,eAAe,QAAQ,MAAM,QAAQ,aAAa,eAAe,CAAC;AAAA,E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