@bessemer/cornerstone 0.5.53 → 0.5.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts.map +1 -1
- package/dist/array.js +13 -16
- package/dist/array.js.map +1 -1
- package/dist/assertion.d.ts +6 -6
- package/dist/assertion.d.ts.map +1 -1
- package/dist/assertion.js +21 -15
- package/dist/assertion.js.map +1 -1
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +3 -4
- package/dist/async.js.map +1 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +17 -22
- package/dist/cache.js.map +1 -1
- package/dist/combinable.d.ts.map +1 -1
- package/dist/combinable.js +4 -5
- package/dist/combinable.js.map +1 -1
- package/dist/comparator.d.ts.map +1 -1
- package/dist/comparator.js +5 -8
- package/dist/comparator.js.map +1 -1
- package/dist/content.d.ts +9 -9
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js +13 -18
- package/dist/content.js.map +1 -1
- package/dist/date.d.ts.map +1 -1
- package/dist/date.js +2 -2
- package/dist/date.js.map +1 -1
- package/dist/either.d.ts +1 -0
- package/dist/either.d.ts.map +1 -1
- package/dist/either.js +3 -2
- package/dist/either.js.map +1 -1
- package/dist/error-event.d.ts +2 -2
- package/dist/error-event.d.ts.map +1 -1
- package/dist/error-event.js +69 -51
- package/dist/error-event.js.map +1 -1
- package/dist/error.js +2 -2
- package/dist/error.js.map +1 -1
- package/dist/expression/array-expression.js +3 -3
- package/dist/expression/array-expression.js.map +1 -1
- package/dist/expression/core-expression.d.ts +6 -6
- package/dist/expression/core-expression.d.ts.map +1 -1
- package/dist/expression/core-expression.js +6 -9
- package/dist/expression/core-expression.js.map +1 -1
- package/dist/expression/expression-evaluator.js +3 -3
- package/dist/expression/expression-evaluator.js.map +1 -1
- package/dist/expression/expression-mapper.js +3 -3
- package/dist/expression/expression-mapper.js.map +1 -1
- package/dist/expression/expression.d.ts +6 -5
- package/dist/expression/expression.d.ts.map +1 -1
- package/dist/expression/expression.js +2 -2
- package/dist/expression/expression.js.map +1 -1
- package/dist/expression/internal.d.ts.map +1 -1
- package/dist/expression/internal.js +3 -3
- package/dist/expression/internal.js.map +1 -1
- package/dist/expression/numeric-expression.d.ts +5 -5
- package/dist/expression/numeric-expression.d.ts.map +1 -1
- package/dist/expression/numeric-expression.js +10 -11
- package/dist/expression/numeric-expression.js.map +1 -1
- package/dist/hex-code.d.ts +2 -2
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +1 -1
- package/dist/hex-code.js.map +1 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +3 -3
- package/dist/json.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +9 -10
- package/dist/logger.js.map +1 -1
- package/dist/misc.d.ts.map +1 -1
- package/dist/misc.js +3 -4
- package/dist/misc.js.map +1 -1
- package/dist/patch.d.ts.map +1 -1
- package/dist/patch.js +5 -6
- package/dist/patch.js.map +1 -1
- package/dist/property.d.ts.map +1 -1
- package/dist/property.js +4 -5
- package/dist/property.js.map +1 -1
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js +3 -4
- package/dist/range.js.map +1 -1
- package/dist/reference.d.ts +2 -1
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +10 -13
- package/dist/reference.js.map +1 -1
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +2 -3
- package/dist/resource.js.map +1 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +5 -6
- package/dist/result.js.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +9 -14
- package/dist/retry.js.map +1 -1
- package/dist/rich-text.js +2 -2
- package/dist/rich-text.js.map +1 -1
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +4 -6
- package/dist/signature.js.map +1 -1
- package/dist/sql/sql-expression-parser.d.ts.map +1 -1
- package/dist/sql/sql-expression-parser.js +14 -18
- package/dist/sql/sql-expression-parser.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +7 -9
- package/dist/store.js.map +1 -1
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +2 -2
- package/dist/string.js.map +1 -1
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js +12 -12
- package/dist/tag.js.map +1 -1
- package/dist/ulid.d.ts.map +1 -1
- package/dist/ulid.js +3 -4
- package/dist/ulid.js.map +1 -1
- package/dist/uri.d.ts.map +1 -1
- package/dist/uri.js +50 -52
- package/dist/uri.js.map +1 -1
- package/dist/url.d.ts +2 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +19 -28
- package/dist/url.js.map +1 -1
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +5 -7
- package/dist/uuid.js.map +1 -1
- package/package.json +1 -1
package/dist/comparator.js
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
// src/comparator.ts
|
2
|
-
import {
|
3
|
-
import { isNumber } from "@bessemer/cornerstone/math";
|
4
|
-
import { isDate } from "@bessemer/cornerstone/date";
|
5
|
-
import { isBoolean } from "@bessemer/cornerstone/object";
|
2
|
+
import { Dates, Maths, Objects, Strings } from "@bessemer/cornerstone";
|
6
3
|
var aggregate = (comparators) => {
|
7
4
|
return (first, second) => {
|
8
5
|
if (first === second) {
|
@@ -30,13 +27,13 @@ var natural = () => {
|
|
30
27
|
return aggregate([
|
31
28
|
nullsLast(),
|
32
29
|
(first, second) => {
|
33
|
-
if (isString(first) && isString(second)) {
|
30
|
+
if (Strings.isString(first) && Strings.isString(second)) {
|
34
31
|
return first.localeCompare(second);
|
35
|
-
} else if (isNumber(first) && isNumber(second)) {
|
32
|
+
} else if (Maths.isNumber(first) && Maths.isNumber(second)) {
|
36
33
|
return first - second;
|
37
|
-
} else if (isDate(first) && isDate(second)) {
|
34
|
+
} else if (Dates.isDate(first) && Dates.isDate(second)) {
|
38
35
|
return first.getTime() - second.getTime();
|
39
|
-
} else if (isBoolean(first) && isBoolean(second)) {
|
36
|
+
} else if (Objects.isBoolean(first) && Objects.isBoolean(second)) {
|
40
37
|
if (first !== second) {
|
41
38
|
return second ? 1 : 0;
|
42
39
|
} else {
|
package/dist/comparator.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import { Dates, Maths, Objects, Strings } from '@bessemer/cornerstone'\nimport { BasicType } from '@bessemer/cornerstone/types'\n\nexport type Comparator<T> = (first: T, second: T) => number\n\nexport const aggregate = <T>(comparators: Array<Comparator<T>>): Comparator<T> => {\n return (first, second) => {\n if (first === second) {\n return 0\n }\n\n for (const comparator of comparators) {\n const result = comparator(first, second)\n if (result !== 0) {\n return result\n }\n }\n\n return 0\n }\n}\n\nexport const compareBy = <T, N>(mapper: (element: T) => N, comparator: Comparator<N>): Comparator<T> => {\n return (first, second) => comparator(mapper(first), mapper(second))\n}\n\nexport const reverse = <T>(comparator: Comparator<T>): Comparator<T> => {\n return (first, second) => -comparator(first, second)\n}\n\nexport const trueFirst = (): Comparator<boolean> => {\n return (first, second) => natural()(first ? 1 : 0, second ? 1 : 0)\n}\n\nexport const natural = (): Comparator<BasicType | null> => {\n // Comparing by nulls first allows us to assume the elements are non-null for future comparisons\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (Strings.isString(first) && Strings.isString(second)) {\n return first.localeCompare(second)\n } else if (Maths.isNumber(first) && Maths.isNumber(second)) {\n return first! - second!\n } else if (Dates.isDate(first) && Dates.isDate(second)) {\n return first.getTime() - second.getTime()\n } else if (Objects.isBoolean(first) && Objects.isBoolean(second)) {\n if(first !== second) {\n return second ? 1 : 0\n }\n else {\n return 0\n }\n } {\n return 0\n }\n },\n ])\n}\n\nexport function matchedFirst<T>(target: T): Comparator<T | null> {\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (first === target && second !== target) {\n return -1\n } else if (first !== target && second === target) {\n return 1\n } else {\n return 0\n }\n },\n ])\n}\n\nexport const nullsLast = <T>(): Comparator<T> => {\n return (first, second) => {\n if (first === null) {\n return 1\n }\n if (second === null) {\n return -1\n }\n\n return 0\n }\n}\n"],"mappings":";AAAA,SAAS,OAAO,OAAO,SAAS,eAAe;AAKxC,IAAM,YAAY,CAAI,gBAAqD;AAChF,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,QAAQ;AACpB,aAAO;AAAA,IACT;AAEA,eAAW,cAAc,aAAa;AACpC,YAAM,SAAS,WAAW,OAAO,MAAM;AACvC,UAAI,WAAW,GAAG;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,IAAM,YAAY,CAAO,QAA2B,eAA6C;AACtG,SAAO,CAAC,OAAO,WAAW,WAAW,OAAO,KAAK,GAAG,OAAO,MAAM,CAAC;AACpE;AAEO,IAAM,UAAU,CAAI,eAA6C;AACtE,SAAO,CAAC,OAAO,WAAW,CAAC,WAAW,OAAO,MAAM;AACrD;AAEO,IAAM,YAAY,MAA2B;AAClD,SAAO,CAAC,OAAO,WAAW,QAAQ,EAAE,QAAQ,IAAI,GAAG,SAAS,IAAI,CAAC;AACnE;AAEO,IAAM,UAAU,MAAoC;AAEzD,SAAO,UAAU;AAAA,IACf,UAAU;AAAA,IACV,CAAC,OAAO,WAAW;AACjB,UAAI,QAAQ,SAAS,KAAK,KAAK,QAAQ,SAAS,MAAM,GAAG;AACvD,eAAO,MAAM,cAAc,MAAM;AAAA,MACnC,WAAW,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,MAAM,GAAG;AAC1D,eAAO,QAAS;AAAA,MAClB,WAAW,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO,MAAM,GAAG;AACtD,eAAO,MAAM,QAAQ,IAAI,OAAO,QAAQ;AAAA,MAC1C,WAAW,QAAQ,UAAU,KAAK,KAAK,QAAQ,UAAU,MAAM,GAAG;AAChE,YAAG,UAAU,QAAQ;AACnB,iBAAO,SAAS,IAAI;AAAA,QACtB,OACK;AACH,iBAAO;AAAA,QACT;AAAA,MACF;AAAE;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,SAAS,aAAgB,QAAiC;AAC/D,SAAO,UAAU;AAAA,IACf,UAAU;AAAA,IACV,CAAC,OAAO,WAAW;AACjB,UAAI,UAAU,UAAU,WAAW,QAAQ;AACzC,eAAO;AAAA,MACT,WAAW,UAAU,UAAU,WAAW,QAAQ;AAChD,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,IAAM,YAAY,MAAwB;AAC/C,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,QAAI,WAAW,MAAM;AACnB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/content.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { NominalType } from '@bessemer/cornerstone/types';
|
|
3
3
|
import { AbstractApplicationContext } from '@bessemer/cornerstone/context';
|
4
4
|
import { RichTextJson } from '@bessemer/cornerstone/rich-text';
|
5
5
|
import { Tag } from '@bessemer/cornerstone/tag';
|
6
|
-
import
|
6
|
+
import { ZodType } from 'zod';
|
7
7
|
export type ContentSector = NominalType<string, 'ContentSector'>;
|
8
8
|
export declare const ContentSectorSchema: ZodType<ContentSector>;
|
9
9
|
export type ContentKey = NominalType<string, 'ContentKey'>;
|
@@ -12,19 +12,19 @@ export type ContentType<Data = unknown> = NominalType<string, ['ContentType', Da
|
|
12
12
|
export declare const ContentTypeSchema: ZodType<ContentType>;
|
13
13
|
export type ContentReference = Reference<'Content'>;
|
14
14
|
type ContentDataType<Type> = Type extends ContentType<infer Data> ? Data : never;
|
15
|
-
export declare const ContentDataSchema:
|
16
|
-
key:
|
17
|
-
type:
|
18
|
-
data:
|
19
|
-
sector:
|
20
|
-
}, "strip",
|
21
|
-
type: string & import("@bessemer/cornerstone/types").NominalTyping<["ContentType", unknown]>;
|
15
|
+
export declare const ContentDataSchema: import("zod").ZodObject<{
|
16
|
+
key: ZodType<ContentKey, import("zod").ZodTypeDef, ContentKey>;
|
17
|
+
type: ZodType<ContentType<unknown>, import("zod").ZodTypeDef, ContentType<unknown>>;
|
18
|
+
data: import("zod").ZodUnknown;
|
19
|
+
sector: import("zod").ZodNullable<ZodType<ContentSector, import("zod").ZodTypeDef, ContentSector>>;
|
20
|
+
}, "strip", import("zod").ZodTypeAny, {
|
22
21
|
key: string & import("@bessemer/cornerstone/types").NominalTyping<"ContentKey">;
|
22
|
+
type: string & import("@bessemer/cornerstone/types").NominalTyping<["ContentType", unknown]>;
|
23
23
|
sector: ContentSector | null;
|
24
24
|
data?: unknown;
|
25
25
|
}, {
|
26
|
-
type: string & import("@bessemer/cornerstone/types").NominalTyping<["ContentType", unknown]>;
|
27
26
|
key: string & import("@bessemer/cornerstone/types").NominalTyping<"ContentKey">;
|
27
|
+
type: string & import("@bessemer/cornerstone/types").NominalTyping<["ContentType", unknown]>;
|
28
28
|
sector: ContentSector | null;
|
29
29
|
data?: unknown;
|
30
30
|
}>;
|
package/dist/content.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAA;AAC/C,OAAO,E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AAC,CAAA;CAC3F,CAAA;AAGD,eAAO,MAAM,gBAAgB,GAAU,kBAAkB,SAAS,0BAA0B,EAC1F,SAAS,KAAK,CAAC,WAAW,CAAC,EAC3B,aAAa,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,EACzD,SAAS,kBAAkB,KAC1B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAa5B,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;IAC9H,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,EAC7F,KAAK,UAAU,EACf,MAAM,IAAI,EACV,MAAM,IAAI,EACV,UAAU;IAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,KACtD,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAS9B,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,kBAAkB,SAAS,0BAA0B,EAClF,SAAS,KAAK,CAAC,iBAAiB,CAAC,EACjC,cAAc,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,KACzD,eAAe,CAAC,kBAAkB,CA2BpC,CAAA"}
|
package/dist/content.js
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
// src/content.ts
|
2
|
-
import {
|
3
|
-
import { resolveBy } from "@bessemer/cornerstone/tag";
|
4
|
-
import Zod from "zod";
|
5
|
-
import { contains, first, groupBy } from "@bessemer/cornerstone/array";
|
6
|
-
import { isNil, isPresent } from "@bessemer/cornerstone/object";
|
7
|
-
import { generateString } from "@bessemer/cornerstone/ulid";
|
2
|
+
import { Arrays, Objects, References, Tags, Ulids, Zod } from "@bessemer/cornerstone";
|
8
3
|
var ContentSectorSchema = Zod.string();
|
9
4
|
var ContentKeySchema = Zod.string();
|
10
5
|
var ContentTypeSchema = Zod.string();
|
@@ -25,10 +20,10 @@ var ContentDisplayTypes;
|
|
25
20
|
})(ContentDisplayTypes || (ContentDisplayTypes = {}));
|
26
21
|
var TextContentType = "Text";
|
27
22
|
var normalizeContent = async (content, normalizers, context) => {
|
28
|
-
const groupedContent = groupBy(content, (it) => it.type);
|
23
|
+
const groupedContent = Arrays.groupBy(content, (it) => it.type);
|
29
24
|
const normalizedGroupedContent = Object.entries(groupedContent).map(async ([type, values]) => {
|
30
25
|
const normalizer = normalizers.find((it) => it.type === type);
|
31
|
-
if (isNil(normalizer)) {
|
26
|
+
if (Objects.isNil(normalizer)) {
|
32
27
|
return values;
|
33
28
|
}
|
34
29
|
return await normalizer.normalize(values, context);
|
@@ -38,7 +33,7 @@ var normalizeContent = async (content, normalizers, context) => {
|
|
38
33
|
};
|
39
34
|
var staticData = (key, type, data, options) => {
|
40
35
|
return {
|
41
|
-
reference: reference(generateString(), "Content"),
|
36
|
+
reference: References.reference(Ulids.generateString(), "Content"),
|
42
37
|
key,
|
43
38
|
type,
|
44
39
|
data,
|
@@ -49,22 +44,22 @@ var staticData = (key, type, data, options) => {
|
|
49
44
|
var staticProvider = (content, normalizers) => {
|
50
45
|
return {
|
51
46
|
async fetchContentByIds(references, context) {
|
52
|
-
const matchingContent = content.filter((it) => contains(references, it.reference));
|
47
|
+
const matchingContent = content.filter((it) => Arrays.contains(references, it.reference));
|
53
48
|
return normalizeContent(matchingContent, normalizers ?? [], context);
|
54
49
|
},
|
55
50
|
async fetchContentByKeys(keys, tags, context) {
|
56
|
-
const matchingContent = content.filter((it) => contains(keys, it.key));
|
57
|
-
const resolvedContent = Object.values(groupBy(matchingContent, (it) => it.key)).map((it) => {
|
58
|
-
const resolvedContent2 = resolveBy(it, (it2) => it2.tags ?? [], tags);
|
59
|
-
return first(resolvedContent2);
|
51
|
+
const matchingContent = content.filter((it) => Arrays.contains(keys, it.key));
|
52
|
+
const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {
|
53
|
+
const resolvedContent2 = Tags.resolveBy(it, (it2) => it2.tags ?? [], tags);
|
54
|
+
return Arrays.first(resolvedContent2);
|
60
55
|
});
|
61
56
|
return normalizeContent(resolvedContent, normalizers ?? [], context);
|
62
57
|
},
|
63
58
|
async fetchContentBySectors(sectors, tags, context) {
|
64
|
-
const matchingContent = content.filter((it) => isPresent(it.sector)).filter((it) => contains(sectors, it.sector));
|
65
|
-
const resolvedContent = Object.values(groupBy(matchingContent, (it) => it.key)).map((it) => {
|
66
|
-
const resolvedContent2 = resolveBy(it, (it2) => it2.tags ?? [], tags);
|
67
|
-
return first(resolvedContent2);
|
59
|
+
const matchingContent = content.filter((it) => Objects.isPresent(it.sector)).filter((it) => Arrays.contains(sectors, it.sector));
|
60
|
+
const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {
|
61
|
+
const resolvedContent2 = Tags.resolveBy(it, (it2) => it2.tags ?? [], tags);
|
62
|
+
return Arrays.first(resolvedContent2);
|
68
63
|
});
|
69
64
|
return normalizeContent(resolvedContent, normalizers ?? [], context);
|
70
65
|
}
|
package/dist/content.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/content.ts"],"sourcesContent":["import { Referencable,
|
1
|
+
{"version":3,"sources":["../src/content.ts"],"sourcesContent":["import { Referencable, Reference, ReferenceType } from '@bessemer/cornerstone/reference'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { AbstractApplicationContext } from '@bessemer/cornerstone/context'\nimport { Arrays, Objects, References, Tags, Ulids, Zod } from '@bessemer/cornerstone'\nimport { RichTextJson } from '@bessemer/cornerstone/rich-text'\nimport { Tag } from '@bessemer/cornerstone/tag'\nimport { ZodType } from 'zod'\n\nexport type ContentSector = NominalType<string, 'ContentSector'>\nexport const ContentSectorSchema: ZodType<ContentSector> = Zod.string()\n\nexport type ContentKey = NominalType<string, 'ContentKey'>\nexport const ContentKeySchema: ZodType<ContentKey> = Zod.string()\n\nexport type ContentType<Data = unknown> = NominalType<string, ['ContentType', Data]>\nexport const ContentTypeSchema: ZodType<ContentType> = Zod.string()\n\nexport type ContentReference = Reference<'Content'>\n\ntype ContentDataType<Type> = Type extends ContentType<infer Data> ? Data : never\n\nexport const ContentDataSchema = Zod.object({\n key: ContentKeySchema,\n type: ContentTypeSchema,\n data: Zod.unknown(),\n sector: ContentSectorSchema.nullable(),\n})\n\nexport type ContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = Referencable<ContentReference> & {\n key: ContentKey\n type: Type\n data: Data\n sector: ContentSector | null\n}\n\nexport type ContentTypeConstructor<Content extends ContentData> = Content['type']\n\nexport type ContentDisplayType = NominalType<string, 'ContentDisplayType'>\n\nexport namespace ContentDisplayTypes {\n export const Default: ContentDisplayType = 'Default'\n export const Label: ContentDisplayType = 'Label'\n export const Desktop: ContentDisplayType = 'Desktop'\n export const Mobile: ContentDisplayType = 'Mobile'\n export const Modal: ContentDisplayType = 'Modal'\n export const Tooltip: ContentDisplayType = 'Tooltip'\n}\n\nexport const TextContentType: ContentType<RichTextJson> = 'Text'\nexport type TextContent = ContentData<typeof TextContentType>\n\nexport interface ContentProvider<ContextType extends AbstractApplicationContext = AbstractApplicationContext> {\n fetchContentByIds: (references: Array<ReferenceType<ContentReference>>, context: ContextType) => Promise<Array<ContentData>>\n\n fetchContentByKeys: (keys: Array<ContentKey>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>\n\n fetchContentBySectors: (sectors: Array<ContentSector>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>\n}\n\nexport type ContentNormalizer<\n ApplicationContext extends AbstractApplicationContext = AbstractApplicationContext,\n Type extends ContentData = ContentData\n> = {\n type: Type['type']\n normalize: (data: Array<ContentData>, context: ApplicationContext) => Promise<Array<Type>>\n}\n\n// TODO might be more efficient to put the normalizers in a map at some point\nexport const normalizeContent = async <ApplicationContext extends AbstractApplicationContext>(\n content: Array<ContentData>,\n normalizers: Array<ContentNormalizer<ApplicationContext>>,\n context: ApplicationContext\n): Promise<Array<ContentData>> => {\n const groupedContent = Arrays.groupBy(content, (it) => it.type)\n const normalizedGroupedContent = Object.entries(groupedContent).map(async ([type, values]) => {\n const normalizer = normalizers.find((it) => it.type === type)\n if (Objects.isNil(normalizer)) {\n return values\n }\n\n return await normalizer.normalize(values, context)\n })\n\n const normalizedContent = (await Promise.all(normalizedGroupedContent)).flatMap((it) => it)\n return normalizedContent\n}\n\nexport type StaticContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = ContentData<Type, Data> & {\n tags: Array<Tag>\n}\n\nexport const staticData = <Type extends ContentType = ContentType, Data = ContentDataType<Type>>(\n key: ContentKey,\n type: Type,\n data: Data,\n options?: { tags?: Array<Tag>; sector?: ContentSector }\n): StaticContentData<Type, Data> => {\n return {\n reference: References.reference(Ulids.generateString(), 'Content'),\n key,\n type,\n data,\n tags: options?.tags ?? [],\n sector: options?.sector ?? null,\n }\n}\n\nexport const staticProvider = <ApplicationContext extends AbstractApplicationContext>(\n content: Array<StaticContentData>,\n normalizers?: Array<ContentNormalizer<ApplicationContext>>\n): ContentProvider<ApplicationContext> => {\n return {\n async fetchContentByIds(references: Array<ReferenceType<ContentReference>>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Arrays.contains(references, it.reference))\n return normalizeContent(matchingContent, normalizers ?? [], context)\n },\n async fetchContentByKeys(keys: Array<ContentKey>, tags: Array<Tag>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Arrays.contains(keys, it.key))\n\n const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {\n const resolvedContent = Tags.resolveBy(it, (it) => it.tags ?? [], tags)\n return Arrays.first(resolvedContent)!\n })\n\n return normalizeContent(resolvedContent, normalizers ?? [], context)\n },\n async fetchContentBySectors(sectors: Array<ContentSector>, tags: Array<Tag>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Objects.isPresent(it.sector)).filter((it) => Arrays.contains(sectors, it.sector!))\n\n const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {\n const resolvedContent = Tags.resolveBy(it, (it) => it.tags ?? [], tags)\n return Arrays.first(resolvedContent)!\n })\n\n return normalizeContent(resolvedContent, normalizers ?? [], context)\n },\n }\n}\n"],"mappings":";AAGA,SAAS,QAAQ,SAAS,YAAY,MAAM,OAAO,WAAW;AAMvD,IAAM,sBAA8C,IAAI,OAAO;AAG/D,IAAM,mBAAwC,IAAI,OAAO;AAGzD,IAAM,oBAA0C,IAAI,OAAO;AAM3D,IAAM,oBAAoB,IAAI,OAAO;AAAA,EAC1C,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM,IAAI,QAAQ;AAAA,EAClB,QAAQ,oBAAoB,SAAS;AACvC,CAAC;AAaM,IAAU;AAAA,CAAV,CAAUA,yBAAV;AACE,EAAMA,qBAAA,UAA8B;AACpC,EAAMA,qBAAA,QAA4B;AAClC,EAAMA,qBAAA,UAA8B;AACpC,EAAMA,qBAAA,SAA6B;AACnC,EAAMA,qBAAA,QAA4B;AAClC,EAAMA,qBAAA,UAA8B;AAAA,GAN5B;AASV,IAAM,kBAA6C;AAoBnD,IAAM,mBAAmB,OAC9B,SACA,aACA,YACgC;AAChC,QAAM,iBAAiB,OAAO,QAAQ,SAAS,CAAC,OAAO,GAAG,IAAI;AAC9D,QAAM,2BAA2B,OAAO,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,MAAM,MAAM,MAAM;AAC5F,UAAM,aAAa,YAAY,KAAK,CAAC,OAAO,GAAG,SAAS,IAAI;AAC5D,QAAI,QAAQ,MAAM,UAAU,GAAG;AAC7B,aAAO;AAAA,IACT;AAE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AAO,CAAC;AAEhI,YAAM,kBAAkB,OAAO,OAAO,OAAO,QAAQ,iBAAiB,CAAC,OAAO,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO;AACjG,cAAMA,mBAAkB,KAAK,UAAU,IAAI,CAACC,QAAOA,IAAG,QAAQ,CAAC,GAAG,IAAI;AACtE,eAAO,OAAO,MAAMD,gBAAe;AAAA,MACrC,CAAC;AAED,aAAO,iBAAiB,iBAAiB,eAAe,CAAC,GAAG,OAAO;AAAA,IACrE;AAAA,EACF;AACF;","names":["ContentDisplayTypes","resolvedContent","it"]}
|
package/dist/date.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,eAAe,IAAI,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,QAAQ,IAAI,SAAS,EAAY,MAAM,UAAU,CAAA;AAE3I,OAAO,EAAE,QAAQ,
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,eAAe,IAAI,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,QAAQ,IAAI,SAAS,EAAY,MAAM,UAAU,CAAA;AAE3I,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AAEzD,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,oFAqB5C,CAAA;AAED,eAAO,MAAM,MAAM,gCAAU,CAAA;AAE7B,eAAO,MAAM,GAAG,QAAO,IAEtB,CAAA;AAED,eAAO,MAAM,EAAE,GAAI,YAAY,MAAM,KAAG,IAEvC,CAAA;AAED,eAAO,MAAM,eAAe,yBAAmB,CAAA;AAC/C,eAAO,MAAM,QAAQ,kBAAY,CAAA;AACjC,eAAO,MAAM,QAAQ,kBAAY,CAAA;AACjC,eAAO,MAAM,OAAO,iBAAW,CAAA;AAE/B,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,EAAE,UAAU,QAAQ,KAAG,IAAiE,CAAA"}
|
package/dist/date.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// src/date.ts
|
2
2
|
import { addHours as _addHours, addMilliseconds as _addMilliseconds, isAfter as _isAfter, isBefore as _isBefore, parseISO } from "date-fns";
|
3
3
|
import { isDate as _isDate } from "lodash-es";
|
4
|
-
import {
|
4
|
+
import { Durations } from "@bessemer/cornerstone";
|
5
5
|
import Zod from "zod";
|
6
6
|
var buildSchema = (fieldName) => {
|
7
7
|
return Zod.union([
|
@@ -33,7 +33,7 @@ var addMilliseconds = _addMilliseconds;
|
|
33
33
|
var addHours = _addHours;
|
34
34
|
var isBefore = _isBefore;
|
35
35
|
var isAfter = _isAfter;
|
36
|
-
var addDuration = (date, duration) => addMilliseconds(date, toMilliseconds(duration));
|
36
|
+
var addDuration = (date, duration) => addMilliseconds(date, Durations.toMilliseconds(duration));
|
37
37
|
export {
|
38
38
|
addDuration,
|
39
39
|
addHours,
|
package/dist/date.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import { addHours as _addHours, addMilliseconds as _addMilliseconds, isAfter as _isAfter, isBefore as _isBefore, parseISO } from 'date-fns'\nimport { isDate as _isDate } from 'lodash-es'\nimport { Duration
|
1
|
+
{"version":3,"sources":["../src/date.ts"],"sourcesContent":["import { addHours as _addHours, addMilliseconds as _addMilliseconds, isAfter as _isAfter, isBefore as _isBefore, parseISO } from 'date-fns'\nimport { isDate as _isDate } from 'lodash-es'\nimport { Duration } from '@bessemer/cornerstone/duration'\nimport { Durations } from '@bessemer/cornerstone'\nimport Zod from 'zod'\n\nexport const buildSchema = (fieldName: string) => {\n return Zod.union([\n Zod.string({\n required_error: `${fieldName} is required`,\n })\n .trim()\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?)?$/,\n `${fieldName} is an invalid Date. Use YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.sssZ`\n ),\n Zod.date({\n required_error: `${fieldName} is required`,\n }),\n ]).transform((isoString) => {\n const date = new Date(isoString)\n // Additional check to ensure the parsed date is valid\n if (isNaN(date.getTime())) {\n throw new Error('Invalid date')\n }\n return date\n })\n}\n\nexport const isDate = _isDate\n\nexport const now = (): Date => {\n return new Date()\n}\n\nexport const of = (dateString: string): Date => {\n return parseISO(dateString)\n}\n\nexport const addMilliseconds = _addMilliseconds\nexport const addHours = _addHours\nexport const isBefore = _isBefore\nexport const isAfter = _isAfter\n\nexport const addDuration = (date: Date, duration: Duration): Date => addMilliseconds(date, Durations.toMilliseconds(duration))\n"],"mappings":";AAAA,SAAS,YAAY,WAAW,mBAAmB,kBAAkB,WAAW,UAAU,YAAY,WAAW,gBAAgB;AACjI,SAAS,UAAU,eAAe;AAElC,SAAS,iBAAiB;AAC1B,OAAO,SAAS;AAET,IAAM,cAAc,CAAC,cAAsB;AAChD,SAAO,IAAI,MAAM;AAAA,IACf,IAAI,OAAO;AAAA,MACT,gBAAgB,GAAG,SAAS;AAAA,IAC9B,CAAC,EACE,KAAK,EACL;AAAA,MACC;AAAA,MACA,GAAG,SAAS;AAAA,IACd;AAAA,IACF,IAAI,KAAK;AAAA,MACP,gBAAgB,GAAG,SAAS;AAAA,IAC9B,CAAC;AAAA,EACH,CAAC,EAAE,UAAU,CAAC,cAAc;AAC1B,UAAM,OAAO,IAAI,KAAK,SAAS;AAE/B,QAAI,MAAM,KAAK,QAAQ,CAAC,GAAG;AACzB,YAAM,IAAI,MAAM,cAAc;AAAA,IAChC;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEO,IAAM,SAAS;AAEf,IAAM,MAAM,MAAY;AAC7B,SAAO,oBAAI,KAAK;AAClB;AAEO,IAAM,KAAK,CAAC,eAA6B;AAC9C,SAAO,SAAS,UAAU;AAC5B;AAEO,IAAM,kBAAkB;AACxB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,UAAU;AAEhB,IAAM,cAAc,CAAC,MAAY,aAA6B,gBAAgB,MAAM,UAAU,eAAe,QAAQ,CAAC;","names":[]}
|
package/dist/either.d.ts
CHANGED
package/dist/either.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,IAAI,EAAE,UAAU,CAAC,IAAI,CAAA;IACrB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AACD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IACrB,IAAI,EAAE,UAAU,CAAC,KAAK,CAAA;IACtB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;AAE7C,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,IAAI,CAAC,CAAC,CAAuC,CAAA;AAChF,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,CAAC,CAAC,CAAwC,CAAA;AAEnF,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAoC,CAAA;AACxG,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,IAAI,KAAK,CAA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C,CAAA;AAE3G,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAI3E,CAAA"}
|
package/dist/either.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
// src/either.ts
|
2
|
+
import { Eithers } from "@bessemer/cornerstone";
|
2
3
|
var EitherType = /* @__PURE__ */ ((EitherType2) => {
|
3
4
|
EitherType2["Left"] = "Left";
|
4
5
|
EitherType2["Right"] = "Right";
|
@@ -9,8 +10,8 @@ var right = (value) => ({ type: "Right" /* Right */, value });
|
|
9
10
|
var isLeft = (either) => either.type === "Left" /* Left */;
|
10
11
|
var isRight = (either) => either.type === "Right" /* Right */;
|
11
12
|
var split = (array) => {
|
12
|
-
const lefts = array.filter(isLeft).map((it) => it.value);
|
13
|
-
const rights = array.filter(isRight).map((it) => it.value);
|
13
|
+
const lefts = array.filter(Eithers.isLeft).map((it) => it.value);
|
14
|
+
const rights = array.filter(Eithers.isRight).map((it) => it.value);
|
14
15
|
return [lefts, rights];
|
15
16
|
};
|
16
17
|
export {
|
package/dist/either.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/either.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"sources":["../src/either.ts"],"sourcesContent":["import { Eithers } from '@bessemer/cornerstone'\n\nexport enum EitherType {\n Left = 'Left',\n Right = 'Right',\n}\n\nexport type Left<T> = {\n type: EitherType.Left\n value: T\n}\nexport type Right<N> = {\n type: EitherType.Right\n value: N\n}\n\nexport type Either<T, N> = Left<T> | Right<N>\n\nexport const left = <T>(value: T): Left<T> => ({ type: EitherType.Left, value })\nexport const right = <N>(value: N): Right<N> => ({ type: EitherType.Right, value })\n\nexport const isLeft = <T, N>(either: Either<T, N>): either is Left<T> => either.type === EitherType.Left\nexport const isRight = <T, N>(either: Either<T, N>): either is Right<N> => either.type === EitherType.Right\n\nexport const split = <L, R>(array: Array<Either<L, R>>): [Array<L>, Array<R>] => {\n const lefts = array.filter(Eithers.isLeft).map((it) => it.value)\n const rights = array.filter(Eithers.isRight).map((it) => it.value)\n return [lefts, rights]\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAEjB,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAgBL,IAAM,OAAO,CAAI,WAAuB,EAAE,MAAM,mBAAiB,MAAM;AACvE,IAAM,QAAQ,CAAI,WAAwB,EAAE,MAAM,qBAAkB,MAAM;AAE1E,IAAM,SAAS,CAAO,WAA4C,OAAO,SAAS;AAClF,IAAM,UAAU,CAAO,WAA6C,OAAO,SAAS;AAEpF,IAAM,QAAQ,CAAO,UAAqD;AAC/E,QAAM,QAAQ,MAAM,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,OAAO,GAAG,KAAK;AAC/D,QAAM,SAAS,MAAM,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,KAAK;AACjE,SAAO,CAAC,OAAO,MAAM;AACvB;","names":["EitherType"]}
|
package/dist/error-event.d.ts
CHANGED
@@ -36,9 +36,9 @@ export declare class ErrorEventException extends Error {
|
|
36
36
|
export declare const isErrorEvent: (throwable: Throwable) => throwable is ErrorEvent;
|
37
37
|
export declare const isErrorEventException: (throwable: Throwable) => throwable is ErrorEventException;
|
38
38
|
export declare const of: (builder: ErrorEventBuilder) => ErrorEvent;
|
39
|
-
export declare function wrap<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType;
|
40
|
-
export declare function wrap<ReturnType>(resolver: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>;
|
41
39
|
export declare const from: (throwable: Throwable) => ErrorEvent;
|
40
|
+
export declare function propagate<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType;
|
41
|
+
export declare function propagate<ReturnType>(resolver: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>;
|
42
42
|
export declare const findByCodeInCausalChain: (error: ErrorEvent, code: string) => ErrorEvent | undefined;
|
43
43
|
export declare const findInCausalChain: (error: ErrorEvent, predicate: (error: ErrorEvent) => boolean) => ErrorEvent | undefined;
|
44
44
|
export declare const aggregate: (builder: ErrorEventBuilder, causes: Array<ErrorEvent>) => ErrorEvent | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../src/error-event.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"error-event.d.ts","sourceRoot":"","sources":["../src/error-event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAY,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAOhE,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AACxD,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,SAAS,CAAgB,CAAA;AAE/D,MAAM,MAAM,cAAc,CAAC,IAAI,GAAG,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAA;AACpF,eAAO,MAAM,oBAAoB,EAAE,OAAO,CAAC,cAAc,CAAgB,CAAA;AAEzE,QAAA,MAAM,oBAAoB;;;;;;;;;;;;EAIxB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,GAAG;IAChE,MAAM,EAAE,KAAK,CAAC,UAAU,CA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AAE,UAAU,KAAK,OAAO,KAAG,UAAU,GAAG,SAM7G,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,SAAS,iBAAiB,EAAE,QAAQ,KAAK,CAAC,UAAU,CAAC,KAAG,UAAU,GAAG,SAM9F,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,SAAmC,CAAA;AACpE,eAAO,MAAM,iBAAiB,EAAE,SAAmC,CAAA;AACnE,eAAO,MAAM,kBAAkB,EAAE,SAAmC,CAAA;AACpE,eAAO,MAAM,qBAAqB,EAAE,SAAsC,CAAA;AAC1E,eAAO,MAAM,mBAAmB,EAAE,SAAqC,CAAA;AAEvE,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,MAAM,CAA0B,CAAA;AAC3F,eAAO,MAAM,uBAAuB,EAAE,cAAc,CAAC,MAAM,CAAoB,CAAA;AAE/E,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,eAUlD,CAAA;AAEH,eAAO,MAAM,QAAQ,GAAI,UAAU,iBAAiB,eAUjD,CAAA;AAEH,eAAO,MAAM,YAAY,GAAI,UAAU,iBAAiB,eAUrD,CAAA;AAEH,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,eAUlD,CAAA;AAEH,eAAO,MAAM,UAAU,GAAI,UAAU,iBAAiB,eAUnD,CAAA"}
|
package/dist/error-event.js
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
// src/error-event.ts
|
2
|
-
import {
|
2
|
+
import { Arrays, Errors, Objects, Promises } from "@bessemer/cornerstone";
|
3
3
|
import Zod from "zod";
|
4
4
|
import { evaluate } from "@bessemer/cornerstone/lazy";
|
5
|
-
import { isPromise } from "@bessemer/cornerstone/promise";
|
6
|
-
import { findInCausalChain as errorsFindInCausalChain, isError } from "@bessemer/cornerstone/error";
|
7
|
-
import { first } from "@bessemer/cornerstone/array";
|
8
5
|
var ErrorCodeSchema = Zod.string();
|
9
6
|
var ErrorAttributeSchema = Zod.string();
|
10
7
|
var baseErrorEventSchema = Zod.object({
|
@@ -24,7 +21,7 @@ var ErrorEventException = class extends Error {
|
|
24
21
|
}
|
25
22
|
};
|
26
23
|
var isErrorEvent = (throwable) => {
|
27
|
-
if (!isObject(throwable)) {
|
24
|
+
if (!Objects.isObject(throwable)) {
|
28
25
|
return false;
|
29
26
|
}
|
30
27
|
return "code" in throwable && "message" in throwable && "attributes" in throwable && "causes" in throwable;
|
@@ -41,15 +38,34 @@ var of = (builder) => {
|
|
41
38
|
causes: builder.causes ?? []
|
42
39
|
};
|
43
40
|
};
|
44
|
-
|
41
|
+
var from = (throwable) => {
|
42
|
+
if (isErrorEvent(throwable)) {
|
43
|
+
return throwable;
|
44
|
+
}
|
45
|
+
if (!Errors.isError(throwable)) {
|
46
|
+
return unhandled();
|
47
|
+
}
|
48
|
+
const errorEventException = Errors.findInCausalChain(throwable, isErrorEventException);
|
49
|
+
if (Objects.isNil(errorEventException)) {
|
50
|
+
return unhandled();
|
51
|
+
}
|
52
|
+
return errorEventException.errorEvent;
|
53
|
+
};
|
54
|
+
function propagate(resolver, attributes) {
|
45
55
|
const handleError = (error) => {
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
if (isErrorEventException(error)) {
|
57
|
+
const errorEvent = error.errorEvent;
|
58
|
+
errorEvent.attributes = { ...errorEvent.attributes, ...evaluate(attributes) };
|
59
|
+
throw error;
|
60
|
+
} else {
|
61
|
+
const errorEvent = from(error);
|
62
|
+
const contextualizedEvent = of({ ...errorEvent, attributes: { ...errorEvent.attributes, ...evaluate(attributes) } });
|
63
|
+
throw new ErrorEventException(contextualizedEvent, error);
|
64
|
+
}
|
49
65
|
};
|
50
66
|
try {
|
51
67
|
let result = resolver();
|
52
|
-
if (isPromise(result)) {
|
68
|
+
if (Promises.isPromise(result)) {
|
53
69
|
return result.then((it) => it).catch((it) => handleError(it));
|
54
70
|
} else {
|
55
71
|
return result;
|
@@ -58,19 +74,6 @@ function wrap(resolver, attributes) {
|
|
58
74
|
throw handleError(error);
|
59
75
|
}
|
60
76
|
}
|
61
|
-
var from = (throwable) => {
|
62
|
-
if (isErrorEvent(throwable)) {
|
63
|
-
return throwable;
|
64
|
-
}
|
65
|
-
if (!isError(throwable)) {
|
66
|
-
return unhandled();
|
67
|
-
}
|
68
|
-
const errorEventException = errorsFindInCausalChain(throwable, isErrorEventException);
|
69
|
-
if (isNil(errorEventException)) {
|
70
|
-
return unhandled();
|
71
|
-
}
|
72
|
-
return errorEventException.errorEvent;
|
73
|
-
};
|
74
77
|
var findByCodeInCausalChain = (error, code) => {
|
75
78
|
return findInCausalChain(error, (it) => it.code === code);
|
76
79
|
};
|
@@ -78,7 +81,7 @@ var findInCausalChain = (error, predicate) => {
|
|
78
81
|
if (predicate(error)) {
|
79
82
|
return error;
|
80
83
|
}
|
81
|
-
return first(error.causes.map((it) => findInCausalChain(it, predicate)).filter(isPresent));
|
84
|
+
return Arrays.first(error.causes.map((it) => findInCausalChain(it, predicate)).filter(Objects.isPresent));
|
82
85
|
};
|
83
86
|
var aggregate = (builder, causes) => {
|
84
87
|
if (causes.length === 0) {
|
@@ -94,39 +97,54 @@ var BadRequestErrorCode = "error-event.bad-request";
|
|
94
97
|
var RequestCorrelationIdAttribute = "requestCorrelationId";
|
95
98
|
var HttpStatusCodeAttribute = "httpStatusCode";
|
96
99
|
var unhandled = (builder) => of(
|
97
|
-
deepMerge(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
Objects.deepMerge(
|
101
|
+
{
|
102
|
+
code: UnhandledErrorCode,
|
103
|
+
message: "An Unhandled Error has occurred.",
|
104
|
+
attributes: { [HttpStatusCodeAttribute]: 500 }
|
105
|
+
},
|
106
|
+
builder
|
107
|
+
)
|
102
108
|
);
|
103
109
|
var notFound = (builder) => of(
|
104
|
-
deepMerge(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
110
|
+
Objects.deepMerge(
|
111
|
+
{
|
112
|
+
code: NotFoundErrorCode,
|
113
|
+
message: "The requested Resource could not be found.",
|
114
|
+
attributes: { [HttpStatusCodeAttribute]: 404 }
|
115
|
+
},
|
116
|
+
builder
|
117
|
+
)
|
109
118
|
);
|
110
119
|
var unauthorized = (builder) => of(
|
111
|
-
deepMerge(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
120
|
+
Objects.deepMerge(
|
121
|
+
{
|
122
|
+
code: UnauthorizedErrorCode,
|
123
|
+
message: "The requested Resource requires authentication.",
|
124
|
+
attributes: { [HttpStatusCodeAttribute]: 401 }
|
125
|
+
},
|
126
|
+
builder
|
127
|
+
)
|
116
128
|
);
|
117
129
|
var forbidden = (builder) => of(
|
118
|
-
deepMerge(
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
130
|
+
Objects.deepMerge(
|
131
|
+
{
|
132
|
+
code: ForbiddenErrorCode,
|
133
|
+
message: "The requested Resource requires additional permissions to access.",
|
134
|
+
attributes: { [HttpStatusCodeAttribute]: 403 }
|
135
|
+
},
|
136
|
+
builder
|
137
|
+
)
|
123
138
|
);
|
124
139
|
var badRequest = (builder) => of(
|
125
|
-
deepMerge(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
140
|
+
Objects.deepMerge(
|
141
|
+
{
|
142
|
+
code: BadRequestErrorCode,
|
143
|
+
message: "The request is invalid and cannot be processed.",
|
144
|
+
attributes: { [HttpStatusCodeAttribute]: 400 }
|
145
|
+
},
|
146
|
+
builder
|
147
|
+
)
|
130
148
|
);
|
131
149
|
export {
|
132
150
|
BadRequestErrorCode,
|
@@ -149,8 +167,8 @@ export {
|
|
149
167
|
isErrorEventException,
|
150
168
|
notFound,
|
151
169
|
of,
|
170
|
+
propagate,
|
152
171
|
unauthorized,
|
153
|
-
unhandled
|
154
|
-
wrap
|
172
|
+
unhandled
|
155
173
|
};
|
156
174
|
//# sourceMappingURL=error-event.js.map
|
package/dist/error-event.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/error-event.ts"],"sourcesContent":["import { Dictionary, NominalType, 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 { isPromise } from '@bessemer/cornerstone/promise'\nimport { findInCausalChain as errorsFindInCausalChain, isError } from '@bessemer/cornerstone/error'\nimport { first } from '@bessemer/cornerstone/array'\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 = NominalType<string, 'ErrorCode'>\nexport const ErrorCodeSchema: ZodType<ErrorCode> = Zod.string()\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ErrorAttributeSchema: ZodType<ErrorAttribute> = Zod.string()\n\nconst baseErrorEventSchema = Zod.object({\n code: ErrorCodeSchema,\n message: Zod.string(),\n attributes: Zod.record(ErrorAttributeSchema, Zod.unknown()),\n})\n\nexport type ErrorEvent = Zod.infer<typeof baseErrorEventSchema> & {\n causes: Array<ErrorEvent>\n}\n\nconst ErrorEventSchema: ZodType<ErrorEvent> = baseErrorEventSchema.extend({\n causes: Zod.lazy(() => Zod.array(ErrorEventSchema)),\n})\n\n// Builder object that allows for 'partial' representation of ErrorEvents\nexport type ErrorEventBuilder = {\n code: ErrorCode\n message?: string | null\n attributes?: Record<ErrorAttribute, unknown>\n causes?: Array<ErrorEvent>\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 return 'code' in throwable && 'message' in throwable && 'attributes' in throwable && 'causes' in throwable\n}\n\nexport const isErrorEventException = (throwable: Throwable): throwable is ErrorEventException => {\n return throwable instanceof ErrorEventException\n}\n\nexport const of = (builder: ErrorEventBuilder): ErrorEvent => {\n const code = builder.code\n\n return {\n code,\n message: builder.message ?? code,\n attributes: builder.attributes ?? {},\n causes: builder.causes ?? [],\n }\n}\n\nexport function wrap<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType\nexport function wrap<ReturnType>(resolver: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>\nexport function wrap<ReturnType>(\n resolver: () => ReturnType | Promise<ReturnType>,\n attributes: LazyValue<Dictionary<unknown>>\n): ReturnType | Promise<ReturnType> {\n const handleError = (error: Throwable) => {\n const errorEvent = from(error)\n\n const contextualizedEvent = of({ ...errorEvent, attributes: { ...errorEvent.attributes, ...evaluate(attributes) } })\n throw new ErrorEventException(contextualizedEvent, error)\n }\n\n try {\n let result = resolver()\n if (isPromise(result)) {\n return result.then((it) => it).catch((it) => handleError(it))\n } else {\n return result\n }\n } catch (error: Throwable) {\n throw handleError(error)\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 const findByCodeInCausalChain = (error: ErrorEvent, code: string): ErrorEvent | undefined => {\n return findInCausalChain(error, (it) => it.code === code)\n}\n\n/*\n Traverses the causal chain of the ErrorEvent, searching for a predicate that matches (including matching on the parent error event)\n This is useful if you want to find whether or not a given error was caused by a specific failure. The search executes depth-first and\n will return te first matching instance that satisfies the predicate, or undefined otherwise\n */\nexport const findInCausalChain = (error: ErrorEvent, predicate: (error: ErrorEvent) => boolean): ErrorEvent | undefined => {\n if (predicate(error)) {\n return error\n }\n\n return first(error.causes.map((it) => findInCausalChain(it, predicate)).filter(isPresent))\n}\n\nexport const aggregate = (builder: ErrorEventBuilder, causes: Array<ErrorEvent>): ErrorEvent | undefined => {\n if (causes.length === 0) {\n return undefined\n }\n\n return of({ ...builder, causes })\n}\n\nexport const UnhandledErrorCode: ErrorCode = 'error-event.unhandled'\nexport const NotFoundErrorCode: ErrorCode = 'error-event.not-found'\nexport const ForbiddenErrorCode: ErrorCode = 'error-event.forbidden'\nexport const UnauthorizedErrorCode: ErrorCode = 'error-event.unauthorized'\nexport const BadRequestErrorCode: ErrorCode = 'error-event.bad-request'\n\nexport const RequestCorrelationIdAttribute: ErrorAttribute<string> = 'requestCorrelationId'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nexport const unhandled = (builder?: ErrorEventAugment) =>\n of(\n deepMerge(builder, {\n code: UnhandledErrorCode,\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n })\n )\n\nexport const notFound = (builder?: ErrorEventAugment) =>\n of(\n deepMerge(builder, {\n code: NotFoundErrorCode,\n message: 'The requested Resource could not be found.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n })\n )\n\nexport const unauthorized = (builder?: ErrorEventAugment) =>\n of(\n deepMerge(builder, {\n code: UnauthorizedErrorCode,\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n })\n )\n\nexport const forbidden = (builder?: ErrorEventAugment) =>\n of(\n deepMerge(builder, {\n code: ForbiddenErrorCode,\n message: 'The requested Resource requires additional permissions to access.',\n attributes: { [HttpStatusCodeAttribute]: 403 },\n })\n )\n\nexport const badRequest = (builder?: ErrorEventAugment) =>\n of(\n deepMerge(builder, {\n code: BadRequestErrorCode,\n message: 'The request is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400 },\n })\n )\n"],"mappings":";AACA,SAAS,WAAW,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AAkD;AAExD,IAAM,YAAY,CAAC,YACxB;AAAA,EACE,UAAU,SAAS;AAAA,IACjB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;AAEK,IAAM,WAAW,CAAC,YACvB;AAAA,EACE,UAAU,SAAS;AAAA,IACjB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;AAEK,IAAM,eAAe,CAAC,YAC3B;AAAA,EACE,UAAU,SAAS;AAAA,IACjB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;AAEK,IAAM,YAAY,CAAC,YACxB;AAAA,EACE,UAAU,SAAS;AAAA,IACjB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;AAEK,IAAM,aAAa,CAAC,YACzB;AAAA,EACE,UAAU,SAAS;AAAA,IACjB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,EAC/C,CAAC;AACH;","names":[]}
|
1
|
+
{"version":3,"sources":["../src/error-event.ts"],"sourcesContent":["import { Arrays, Errors, Objects, Promises } from '@bessemer/cornerstone'\nimport { Dictionary, NominalType, Throwable } from '@bessemer/cornerstone/types'\nimport { RecordAttribute } from '@bessemer/cornerstone/object'\nimport Zod, { ZodType } from 'zod'\nimport { evaluate, LazyValue } from '@bessemer/cornerstone/lazy'\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 = NominalType<string, 'ErrorCode'>\nexport const ErrorCodeSchema: ZodType<ErrorCode> = Zod.string()\n\nexport type ErrorAttribute<Type = unknown> = RecordAttribute<Type, 'ErrorAttribute'>\nexport const ErrorAttributeSchema: ZodType<ErrorAttribute> = Zod.string()\n\nconst baseErrorEventSchema = Zod.object({\n code: ErrorCodeSchema,\n message: Zod.string(),\n attributes: Zod.record(ErrorAttributeSchema, Zod.unknown()),\n})\n\nexport type ErrorEvent = Zod.infer<typeof baseErrorEventSchema> & {\n causes: Array<ErrorEvent>\n}\n\nconst ErrorEventSchema: ZodType<ErrorEvent> = baseErrorEventSchema.extend({\n causes: Zod.lazy(() => Zod.array(ErrorEventSchema)),\n})\n\n// Builder object that allows for 'partial' representation of ErrorEvents\nexport type ErrorEventBuilder = {\n code: ErrorCode\n message?: string | null\n attributes?: Record<ErrorAttribute, unknown>\n causes?: Array<ErrorEvent>\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 (!Objects.isObject(throwable)) {\n return false\n }\n\n return 'code' in throwable && 'message' in throwable && 'attributes' in throwable && 'causes' in throwable\n}\n\nexport const isErrorEventException = (throwable: Throwable): throwable is ErrorEventException => {\n return throwable instanceof ErrorEventException\n}\n\nexport const of = (builder: ErrorEventBuilder): ErrorEvent => {\n const code = builder.code\n\n return {\n code,\n message: builder.message ?? code,\n attributes: builder.attributes ?? {},\n causes: builder.causes ?? [],\n }\n}\n\nexport const from = (throwable: Throwable): ErrorEvent => {\n if (isErrorEvent(throwable)) {\n return throwable\n }\n\n if (!Errors.isError(throwable)) {\n return unhandled()\n }\n\n const errorEventException = Errors.findInCausalChain(throwable, isErrorEventException) as ErrorEventException | undefined\n if (Objects.isNil(errorEventException)) {\n return unhandled()\n }\n\n return errorEventException.errorEvent\n}\n\nexport function propagate<ReturnType>(runnable: () => ReturnType, attributes: LazyValue<Dictionary<unknown>>): ReturnType\nexport function propagate<ReturnType>(resolver: () => Promise<ReturnType>, attributes: LazyValue<Dictionary<unknown>>): Promise<ReturnType>\nexport function propagate<ReturnType>(\n resolver: () => ReturnType | Promise<ReturnType>,\n attributes: LazyValue<Dictionary<unknown>>\n): ReturnType | Promise<ReturnType> {\n const handleError = (error: Throwable) => {\n if (isErrorEventException(error)) {\n // We just mutate the existing error event to avoid nested exceptions\n const errorEvent = error.errorEvent\n errorEvent.attributes = { ...errorEvent.attributes, ...evaluate(attributes) }\n throw error\n } else {\n const errorEvent = from(error)\n const contextualizedEvent = of({ ...errorEvent, attributes: { ...errorEvent.attributes, ...evaluate(attributes) } })\n throw new ErrorEventException(contextualizedEvent, error)\n }\n }\n\n try {\n let result = resolver()\n if (Promises.isPromise(result)) {\n return result.then((it) => it).catch((it) => handleError(it))\n } else {\n return result\n }\n } catch (error: Throwable) {\n throw handleError(error)\n }\n}\n\nexport const findByCodeInCausalChain = (error: ErrorEvent, code: string): ErrorEvent | undefined => {\n return findInCausalChain(error, (it) => it.code === code)\n}\n\n/*\n Traverses the causal chain of the ErrorEvent, searching for a predicate that matches (including matching on the parent error event)\n This is useful if you want to find whether or not a given error was caused by a specific failure. The search executes depth-first and\n will return te first matching instance that satisfies the predicate, or undefined otherwise\n */\nexport const findInCausalChain = (error: ErrorEvent, predicate: (error: ErrorEvent) => boolean): ErrorEvent | undefined => {\n if (predicate(error)) {\n return error\n }\n\n return Arrays.first(error.causes.map((it) => findInCausalChain(it, predicate)).filter(Objects.isPresent))\n}\n\nexport const aggregate = (builder: ErrorEventBuilder, causes: Array<ErrorEvent>): ErrorEvent | undefined => {\n if (causes.length === 0) {\n return undefined\n }\n\n return of({ ...builder, causes })\n}\n\nexport const UnhandledErrorCode: ErrorCode = 'error-event.unhandled'\nexport const NotFoundErrorCode: ErrorCode = 'error-event.not-found'\nexport const ForbiddenErrorCode: ErrorCode = 'error-event.forbidden'\nexport const UnauthorizedErrorCode: ErrorCode = 'error-event.unauthorized'\nexport const BadRequestErrorCode: ErrorCode = 'error-event.bad-request'\n\nexport const RequestCorrelationIdAttribute: ErrorAttribute<string> = 'requestCorrelationId'\nexport const HttpStatusCodeAttribute: ErrorAttribute<number> = 'httpStatusCode'\n\nexport const unhandled = (builder?: ErrorEventAugment) =>\n of(\n Objects.deepMerge(\n {\n code: UnhandledErrorCode,\n message: 'An Unhandled Error has occurred.',\n attributes: { [HttpStatusCodeAttribute]: 500 },\n },\n builder\n )\n )\n\nexport const notFound = (builder?: ErrorEventAugment) =>\n of(\n Objects.deepMerge(\n {\n code: NotFoundErrorCode,\n message: 'The requested Resource could not be found.',\n attributes: { [HttpStatusCodeAttribute]: 404 },\n },\n builder\n )\n )\n\nexport const unauthorized = (builder?: ErrorEventAugment) =>\n of(\n Objects.deepMerge(\n {\n code: UnauthorizedErrorCode,\n message: 'The requested Resource requires authentication.',\n attributes: { [HttpStatusCodeAttribute]: 401 },\n },\n builder\n )\n )\n\nexport const forbidden = (builder?: ErrorEventAugment) =>\n of(\n Objects.deepMerge(\n {\n code: ForbiddenErrorCode,\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) =>\n of(\n Objects.deepMerge(\n {\n code: BadRequestErrorCode,\n message: 'The request is invalid and cannot be processed.',\n attributes: { [HttpStatusCodeAttribute]: 400 },\n },\n builder\n )\n )\n"],"mappings":";AAAA,SAAS,QAAQ,QAAQ,SAAS,gBAAgB;AAGlD,OAAO,SAAsB;AAC7B,SAAS,gBAA2B;AAQ7B,IAAM,kBAAsC,IAAI,OAAO;AAGvD,IAAM,uBAAgD,IAAI,OAAO;AAExE,IAAM,uBAAuB,IAAI,OAAO;AAAA,EACtC,MAAM;AAAA,EACN,SAAS,IAAI,OAAO;AAAA,EACpB,YAAY,IA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N,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF;AAEK,IAAM,WAAW,CAAC,YACvB;AAAA,EACE,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF;AAEK,IAAM,eAAe,CAAC,YAC3B;AAAA,EACE,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF;AAEK,IAAM,YAAY,CAAC,YACxB;AAAA,EACE,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF;AAEK,IAAM,aAAa,CAAC,YACzB;AAAA,EACE,QAAQ;AAAA,IACN;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY,EAAE,CAAC,uBAAuB,GAAG,IAAI;AAAA,IAC/C;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/error.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
// src/error.ts
|
2
|
+
import { Objects } from "@bessemer/cornerstone";
|
2
3
|
import { isError as _isError } from "lodash-es";
|
3
|
-
import { isPresent } from "@bessemer/cornerstone/object";
|
4
4
|
var isError = _isError;
|
5
5
|
var findInCausalChain = (error, predicate) => {
|
6
6
|
if (predicate(error)) {
|
7
7
|
return error;
|
8
8
|
}
|
9
|
-
if (isPresent(error.cause) && error.cause instanceof Error) {
|
9
|
+
if (Objects.isPresent(error.cause) && error.cause instanceof Error) {
|
10
10
|
return findInCausalChain(error.cause, predicate);
|
11
11
|
}
|
12
12
|
return void 0;
|
package/dist/error.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/error.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../src/error.ts"],"sourcesContent":["import { Objects } from '@bessemer/cornerstone'\nimport { isError as _isError } from 'lodash-es'\n\nexport const isError = _isError\n\nexport const findInCausalChain = (error: Error, predicate: (error: Error) => boolean): Error | undefined => {\n if (predicate(error)) {\n return error\n }\n\n if (Objects.isPresent(error.cause) && error.cause instanceof Error) {\n return findInCausalChain(error.cause, predicate)\n }\n\n return undefined\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,WAAW,gBAAgB;AAE7B,IAAM,UAAU;AAEhB,IAAM,oBAAoB,CAAC,OAAc,cAA4D;AAC1G,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,UAAU,MAAM,KAAK,KAAK,MAAM,iBAAiB,OAAO;AAClE,WAAO,kBAAkB,MAAM,OAAO,SAAS;AAAA,EACjD;AAEA,SAAO;AACT;","names":[]}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// src/expression/array-expression.ts
|
2
2
|
import { defineExpression } from "@bessemer/cornerstone/expression/internal";
|
3
|
-
import {
|
3
|
+
import { Arrays } from "@bessemer/cornerstone";
|
4
4
|
var ConcatenateExpression = defineExpression({
|
5
5
|
expressionKey: "Array.Concatenate",
|
6
6
|
builder: (operands) => {
|
@@ -8,7 +8,7 @@ var ConcatenateExpression = defineExpression({
|
|
8
8
|
},
|
9
9
|
resolver: ({ operands }, evaluate) => {
|
10
10
|
const values = evaluate(operands).map((it) => evaluate(it));
|
11
|
-
return
|
11
|
+
return Arrays.concatenate(values[0], ...Arrays.rest(values));
|
12
12
|
}
|
13
13
|
});
|
14
14
|
var concatenate = ConcatenateExpression.builder;
|
@@ -19,7 +19,7 @@ var FirstExpression = defineExpression({
|
|
19
19
|
},
|
20
20
|
resolver: ({ operands }, evaluate) => {
|
21
21
|
const values = evaluate(operands).map((it) => evaluate(it));
|
22
|
-
return
|
22
|
+
return Arrays.first(values);
|
23
23
|
}
|
24
24
|
});
|
25
25
|
var first = FirstExpression.builder;
|